Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack and Rollup support #152

Open
larsgw opened this issue Jun 3, 2018 · 15 comments
Open

Webpack and Rollup support #152

larsgw opened this issue Jun 3, 2018 · 15 comments
Labels

Comments

@larsgw
Copy link
Owner

larsgw commented Jun 3, 2018

See #151

@larsgw larsgw added the meta label Jun 3, 2018
@larsgw
Copy link
Owner Author

larsgw commented Aug 23, 2018

Or rollup, I guess...

@FelixBenning
Copy link

Any updates on this? The only thing that attempts to do citations with bibliography seems to be distill. And there are several issues with it:

  • it was recently announced to be on Hiatus and the github project seems to be abandoned
  • You can not have Citations/bibliography without all the CSS, and other stuff added to the distill website.
  • They use bibtex-parse-js under the hood, which was abandoned 5 years ago and has bugs.

So I want to attempt factoring out that citation mechanic as a separate module to allow for something akin to the \textcite{citeKey} \printbibliography mechanic in latex. And of course use a maintained citation parser as a backend. Since distill uses rollup (and rollup seems to be the most modern package manager[?]) I thought I would try to start my project with that. But I am unable to import Cite from this package. I am also relatively new to web development so I am currently at a bit of a loss how I might go about working around this.

@larsgw
Copy link
Owner Author

larsgw commented Apr 17, 2022

I personally never use Webpack and I never got around to try making it work yet. However, I think that it should work mostly apart from an issue that should be fixed in the next release (citation-js/citation-js#156, citation-js/citation-js#150).

@FelixBenning
Copy link

FelixBenning commented Apr 17, 2022

Thank you for the promt response - I just realized that there is also the citation-js repository cf citation-js/citation-js#129. Is the npm package citation-js generated from this repository or the new one? Because the link still points to this repository. Should I use @citation-js/core instead? Because https://citation.js.org/ tells me to use citation-js still.

I am getting some warnings when compiling with rollup, e.g.:

(!) Missing shims for Node.js built-ins
Creating a browser bundle that depends on "path", "url", "stream", "http", "punycode", "https", "zlib" and "querystring". You might need to include https://github.com/snowpackjs/rollup-plugin-polyfill-node
http://localhost:8088 -> C:\Users\felix\code\bibcite\dist
http://localhost:8088 -> C:\Users\felix\code\bibcite\examples
(!) Missing global variable names
Use output.globals to specify browser global variable names corresponding to external modules
child_process (guessing 'require$$0$4')
path (guessing 'require$$1$8')
url (guessing 'require$$2$2')
stream (guessing 'require$$0$3')
http (guessing 'require$$1$7')
punycode (guessing 'require$$0$2')
https (guessing 'require$$4$4')
zlib (guessing 'require$$5')
querystring (guessing 'require$$0$5')
(!) Circular dependencies
node_modules/@citation-js/core/lib/Cite/index.js -> node_modules/@citation-js/core/lib/Cite/log.js -> node_modules/@citation-js/core/lib/Cite/index.js
node_modules/@citation-js/core/lib/Cite/index.js -> node_modules/@citation-js/core/lib/Cite/log.js -> C:\Users\felix\code\bibcite\node_modules\@citation-js\core\lib\Cite\index.js?commonjs-proxy -> node_modules/@citation-js/core/lib/Cite/index.js
node_modules/@citation-js/core/lib/plugins/input/register.js -> node_modules/@citation-js/core/lib/plugins/input/data.js -> node_modules/@citation-js/core/lib/plugins/input/chain.js -> node_modules/@citation-js/core/lib/plugins/input/register.js
...and 4 more

and in the browser Uncaught TypeError: Stream is undefined even though I have the nodePolyfills(), plugin from rollup-plugin-polyfill-node. Oh, and if I don't manually install @rollup/plugin-json, it does not seem to compile at all.

@larsgw
Copy link
Owner Author

larsgw commented Apr 17, 2022

Is the npm package citation-js generated from this repository or the new one? Because the link still points to this repository. Should I use @citation-js/core instead? Because https://citation.js.org/ tells me to use citation-js still.

So the main repository with all the code is https://github.com/citation-js/citation-js, which is published on npm as @citation-js/core and a number of plugins (https://github.com/citation-js/citation-js#plugins). This repository is now a wrapper around the @citation-js/* packages to provide the exact same interface as before. You can use either but @citation-js/core is the main package now (just be sure to include the plugins you need). See also citation-js/citation-js#129.

I am getting some warnings when compiling with rollup

It looks like the main cause is that the browser-specific alternatives to node-fetch and sync-fetch are not being picked up. These dependencies specify an alternative code path in the browser field of package.json, but it looks like this is not picked up by Rollup by default (rollup/rollup#185).

@larsgw larsgw changed the title Webpack support Webpack and Rollup support Apr 17, 2022
@FelixBenning
Copy link

I tried

import { nodeResolve } from "@rollup/plugin-node-resolve";

// ...

    nodeResolve({browser: true}),

but that did not appear to change any of the warnings. I think I'll take a break from this today

@larsgw
Copy link
Owner Author

larsgw commented Apr 17, 2022

Hm, I'll have to try that at some point. Apart from that, let me know if I can help.

@FelixBenning
Copy link

If you want to take a look: https://github.com/FelixBenning/bibcite

it is pretty much a minimum working example at this point since I have just started with the configuration of rollup, optimistically created a bunch of class skeletons and tried to import this library

@larsgw
Copy link
Owner Author

larsgw commented Apr 17, 2022

So by trial and error I found a number of things to improve:

  1. rollup seems to work a lot better if nodeResolve is the first plugin
  2. Cite is imported incorrectly (you need import { Cite } from ...)
  3. you need to load @citation-js/plugin-bibtex to use BibTeX

To solve step 2 and 3 you can also use the npm package citation-js instead of @citation-js/core depending on what you prefer.

@larsgw
Copy link
Owner Author

larsgw commented Apr 17, 2022

Regarding the first point, browser: true is the right way to go but it doesn't get applied because of the order of the plugins.

@FelixBenning
Copy link

Thank you so much! Then I'll switch back from astrocite later

@FelixBenning
Copy link

Okay so I tried all these changes but it already does not like

const bib = new Cite()

the browser says

Uncaught TypeError: citationJs.Cite is not a constructor

and using

const bib = Cite()

results in

Uncaught TypeError: citationJs.Cite is not a function

see commit: https://github.com/FelixBenning/bibcite/tree/8ace4b5b4c0dc60dae1b0e2669a221aa603809c7

@larsgw
Copy link
Owner Author

larsgw commented Apr 19, 2022

Okay so if you use citation-js instead of @citation-js/core you should not use the brackets import { Cite } ... but instead what you had before. Sorry for the confusion.

@FelixBenning
Copy link

I actually switched to citation-js in the hopes of making the errors go away 😂 . I got it to work for citation-js but did not manage to do so for a @citation-js/core and @citation-js/plugin-bibtex. I am not really sure how you activate the plugin so that you can pass bibtex to the Cite constructor again.

Fortunately I have realized that this entire parsing business is orthogonal to my problem anyway. Zotero can in fact export CSL JSON and then I do not actually need any parser. I'll probably still try to enable the use of a parser but probably just as an optional callable passed to my library instead of built in. Then people can use whatever parser they want and I can concentrate on what I want to do right now - a citing framework for html.

@larsgw
Copy link
Owner Author

larsgw commented Apr 19, 2022

Sounds good.

I am not really sure how you activate the plugin so that you can pass bibtex to the Cite constructor again.

Normally this, unless that doesn't work.

import '@citation-js/plugin-bibtex'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants