ericblade / quagga2

An advanced barcode-scanner written in Javascript and TypeScript - Continuation from https://github.com/serratus/quaggajs
MIT License
766 stars 85 forks source link

Publish ECMAScript module instead of CommonJS (Angular) #485

Open WardLootens opened 1 year ago

WardLootens commented 1 year ago

When building an Angular 15 application dependent on quagga2, a warning is now shown:

Warning: path\to\component.ts depends on '@ericblade/quagga2'. CommonJS or AMD dependencies can cause optimization bailouts.

As mentioned here, Angular recommends avoiding CommonJS dependencies.

Are there any plans to convert this to an ECMAScript module?

ericblade commented 1 year ago

@WardLootens apologies, I don't believe I ever saw this, or I would've responded much earlier.

I suspect that making this a module in it's current state is probably quite non-trivial, but if anyone has any suggestions as to how to get there from here, that'd be awesome.

treeder commented 1 year ago

After a quick look through your code, I would suspect you're not too far off. you're already importing and exporting everything much like ES6 (I suppose that's typescript?).

Might be worth a try to set the typescript target to ES6 and see what happens. --target es6

ericblade commented 1 year ago

@treeder bumping TS target up makes absolutely no change to the output that I can see. I've spent the last 2 years buried in C++ land so I'm not entirely up on what current bundling practices are.

Oh, just remembered, we're using webpack to bundle everything... and the webpack in the 1.x branch is really dated. Looks like this will have to be a 2.0 thing... maybe i'll just promote 2.0 soon, as i've pretty much stalled on the major re-writing, and make that 3.0... hmm. at least that would get us up to much more recent dependencies and tools.

treeder commented 1 year ago

@ericblade no worries, it might not be as easy as I suggested (I was just guessing, I'm not a typescript guy). Zxing isn't even ESM ready either so likely wouldn't have been a smooth thing. We ended up taking the raw zxing library and ESMing the whole thing manually, available here: https://github.com/chainparency/zxinger