webpack browserify --ignore等价?

时间:2017-01-26 12:20:11

标签: javascript node.js npm webpack browserify

我有一些代码在浏览器中不起作用,除非我“忽略”两个软件包,我可以使用browserify做到这一点:browserify files.js -i fs-extra -i request --standalone files > files.browserify.js,结果代码正常工作,但如果我尝试这样做使用webpack代码抱怨模块丢失。

...
  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

我怀疑webpack可能没有像browserify那样创建一个“空存根”:--ignore, -i Replace a file with an empty stub. Files can be globs.

我该怎么做才能解决这个问题?

资源

1 个答案:

答案 0 :(得分:4)

您要找的是null-loader,它返回一个空模块:

module: {
    loaders: [
        {
            test: /^(fs-extra|fs|request)$/,
            loader: "null"
        },
        ...
]

安装:

$ npm i -D null-loader