I have some code that doesn't work in the browser unless I "ignore" two packages, I can do this fine with browserify: browserify files.js -i fs-extra -i request --standalone files > files.browserify.js, the resulting code just works, but if I try to do it with webpack the code complains about modules being missing.
...
plugins: [
new webpack.IgnorePlugin(/fs-extra$/),
new webpack.IgnorePlugin(/request$/),
new webpack.IgnorePlugin(/fs$/)
],
...
test.webpack.js:7655 Uncaught Error: Cannot find module "request"
at webpackMissingModule (test.webpack.js:7655)
at Object.exports.byteLength (test.webpack.js:7655)
at __webpack_require__ (test.webpack.js:20)
at Object.<anonymous> (test.webpack.js:17012)
at __webpack_require__ (test.webpack.js:20)
at test.webpack.js:66
at test.webpack.js:69
I suspect that maybe webpack doesn't create an "empty stub" like browserify does: --ignore, -i Replace a file with an empty stub. Files can be globs..
What can I do to fix this?
What you're looking for is null-loader which returns an empty module:
module: {
loaders: [
{
test: /^(fs-extra|fs|request)$/,
loader: "null"
},
...
]
To install:
$ npm i -D null-loader
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With