lindell / JsBarcode

Barcode generation library written in JavaScript that works in both the browser and on Node.js
http://lindell.me/JsBarcode
MIT License
5.45k stars 1.1k forks source link

The size in webpack #200

Open bowencool opened 6 years ago

bowencool commented 6 years ago

The parsed size is too huge.(webpack^2.6.1) tim 20171107173147

# It doesn't work. 
# How to import a single sub library?
import JsBarcode from 'jsbarcode/bin/barcodes/CODE128'
lindell commented 6 years ago

Is this really before any tree shaking has been made? I see a lot of things that should be automatically removed by webpack while compiling.

bowencool commented 6 years ago

Like this? tim 20171108084819

jonkoops commented 6 years ago

@lindell correct me if I am wrong but I don't believe dead code elimination is a silver bullet here. How would the code be be eliminated if all barcode types are loaded in the main file (see: https://github.com/lindell/JsBarcode/blob/master/src/JsBarcode.js)? That would require some serious introspection I doubt UglifyJS can actually do. I might be wrong, but from what I can see in the bundle that we're pulling through it it is still present afterwards.

screen shot 2018-04-10 at 16 13 39

Perhaps it would make sense to use a setup where one can load the different bar codes & renderers in a modular fashion?

SanichKotikov commented 6 years ago

I suppose the main part/api of the library should be rewritten to support tree shaking.

jonkoops commented 6 years ago

These are my findings, perhaps it would be good to check to be certain I am not operating on false assumptions.

yangjocy commented 6 years ago

Can you share the tool which build an analysis image? Looks cool.

bowencool commented 6 years ago

@yangjocy webpack-bundle-analyzer

Tusko commented 5 years ago

+1 How to import a single sub-library?