webpack:ignoreplugin引发未找到模块错误

时间:2020-05-09 11:06:24

标签: webpack

详细信息:

webpack版本:^ 5.0.0-beta.16

webpack.config.js

module.exports = {
  mode: 'development',
  context: path.resolve(__dirname, 'packages'),
  entry: {
    shared: ['./utils/src/index.ts'],
    button: { import: ['./input/src/index.ts', './someanotherJSfile'], dependOn: 'shared' }
  },
  plugins: [
    new webpack.IgnorePlugin({
      checkResource(resource) {
        if (resource.includes('@component/utils')) {
          return true;
        } else {
          return false;
        }
      }
    });
  ]
}

尝试使用IgnorePlugin时出现错误module not found。我怎么摆脱这个错误?

注意-我不能使用externals

1 个答案:

答案 0 :(得分:0)

尝试使用 __non_webpack_require__ 而不是 require

我在这里找到了解决方案: Ignoring specific require()s in Webpack?