pdfjs
pdfjs copied to clipboard
Convert to es6 modules
Before leaving alpha, the library should be converted to using es6 modules.
Anyone aware of a tool to automatically convert a library to es6 modules?
While I did an initial conversion, I am not yet sure how to handle the fact that pdfjs should work for both server and client. Since Node.js requires the file extension of .mjs
Hello have a look here https://github.com/nolanlawson/cjs-to-es6
Other ideas on stackoverflow https://stackoverflow.com/questions/43106130/convert-existing-legacy-library-to-es6-module
Hi @jpbourgeon, thanks for the links. I have already converted the library in a local branch, but was not able to find a good es6 modules solution for libraries that target both server (Node.js) and client π
Would it help to split the library into two components and take advantage of npmjs namespaces?
Something like @pdfjs/server
and @pdfjs/browser
I guess there are the following options.
1) Write client-side ES modules (.js)
- β does work with babel
- β
named imports work (e.g.
import {Document} from "pdfjs"
- β does not work with Node.js ES modules (since .mjs extension required)
- β does not work with
require
- β‘οΈ the code has to be transpiled back to common-js and additionally included in the module
2) Write server-side ES modules (.mjs)
- β does work with babel
- β
named imports work (e.g.
import {Document} from "pdfjs"
- β does work with Node.js ES modules
- β does not work with
require
- β‘οΈ the code still has to be transpiled back to CJS modules to get
require
to work
3) Keep CJS modules
- β does work with babel
- β named imports do not work (e.g.
import {Document} from "pdfjs"
) - β can be loaded from Node.js ES modules
- β
does work with
require
- β‘οΈ only drawback seems to be that we have to write
import * as pdf from "pdfjs"
when loadingpdfjs
from ES modules (instead of being able to import named exportsimport {Document} from "pdfjs"
)
In Summary, either transpile the code for Node.js usage or live with import {Document} from "pdfjs"
. TBH, I really dislike both options π
The conversion happens here https://github.com/rkusa/pdfjs/tree/es6-modules Though, the branch is unfortunately not green yet
Would it be of interest to move to TS instead of ES6?
Would it be of interest to move to TS instead of ES6?
I've recently had the pleasure to work on a TypeScript codebase [1] using WebStorm [2]Β and I want to report that the overall experience is absolutely amazing and totally washed away any hesitations I had regarding TypeScript. Finally, I feel like I can get similar productive with JavaScript as I am with Python. ES6 did not give me that feeling yet.
[1] https://github.com/hiveeyes/grafana-worldmap-panel [2] https://www.jetbrains.com/webstorm/
@rkusa: Amazing project, greetings from Berlin and keep up the spirit!
My pet project is https://github.com/AllNamesRTaken/GoodCore outside workhours and i could help out is needed.
@AllNamesRTaken: Sounds interesting, thanks for letting us know. Star-given ;].
Would it be of interest to move to TS instead of ES6?
I am, generally speaking, not opposed to TS.
I've recently had the pleasure to work on a TypeScript codebase [1] using WebStorm [2] and I want to report that the overall experience is absolutely amazing and totally washed away any hesitations I had regarding TypeScript.
I can confirm that. In my day job, I also work more with TS than JS and the whole TS dev experience (editor integration, less errors when refactoring, ...) is superior than JS ...
What currently holds me off from converting the codebase to TS:
- I always disliked Coffeescript projects (example works for all other languages that compile to JS), because of the higher entry barrier for submitting a contribution - I am a bit concerned that it might be similar for people when it comes to TS ... though, I think the advantages of TS a greater than my concerns here
- The effort required to convert it
- I am not sure if I'd rather rewrite the lib in something that compiles to wasm (something that would be cooler for my personal use-case of the lib)