Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack browserify --ignore equivalent?

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?

Resources

  • https://webpack.github.io/docs/webpack-for-browserify-users.html#ignore
  • https://webpack.github.io/docs/list-of-plugins.html#ignoreplugin
like image 765
01AutoMonkey Avatar asked Mar 09 '26 08:03

01AutoMonkey


1 Answers

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
like image 157
Stefan Dragnev Avatar answered Mar 11 '26 21:03

Stefan Dragnev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!