I was able to get xlsx working with webpack thanks to the wonderful suggestion from @whytheday in #285. However, I still get the following build warning from webpack:
WARNING in ./~/xlsx/jszip.js
Critical dependencies:
12:436-443 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
@ ./~/xlsx/jszip.js 12:436-443
I'm guessing this is because xlsx includes a minified version of jszip. Looking at the code though, it looks to me like it tries to require a global copy prior to falling back to it's local copy...so I'm not totally sure why it seems to be using the minified version. Maybe it's just the fact that it's present that webpack doesn't like.
Either way, does anyone have a workaround for this? Would it be a worthy goal to try to import jszip as a dependency at some point?
have you tried to declare 'xlsx' as external in webpack config? That solved it for me. See: https://webpack.github.io/docs/library-and-externals.html#applications-and-externals
example:
externals: [
// put your node 3rd party libraries which can't be built with webpack here
// (mysql, mongodb, and so on..)
'xlsx'
]
I'm importing xlsx with an ES6 import, so setting XLSX to external caused it to be undefined for me. However, your suggestion sent me in the right direction. I added {'./jszip': 'jszip'} to "externals" in webpack.
So, the full webpack config (combined with the config from @whytheday) is:
node: {
fs: 'empty'
},
externals: [
{ './cptable': 'var cptable' },
{'./jszip': 'jszip'}
]
Perfect...no more warning, and webpack is referencing (and bundling) the jszip source code. Thanks for the help!
:-)
The externals suggestion from @jamesbillinger didn't work for me, but this noParse suggestion did.
Most helpful comment
I'm importing xlsx with an ES6 import, so setting XLSX to external caused it to be undefined for me. However, your suggestion sent me in the right direction. I added
{'./jszip': 'jszip'}to "externals" in webpack.So, the full webpack config (combined with the config from @whytheday) is:
Perfect...no more warning, and webpack is referencing (and bundling) the jszip source code. Thanks for the help!