Webpack 排除文件夹 [英] Webpack Exclude folder

查看:364
本文介绍了Webpack 排除文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 Webpack 推送一个相当大的应用程序,它从两个库文件夹中提取:第三方和 node_modules.我已经为 js 文件设置了规则:

I'm shoving a rather large app through Webpack, which pulls from two library folders: thirdparty and node_modules. I've setup my rule for js files as such:

{
    test: /\.js$/,
    loader: 'babel-loader',
    include: [
      /src\/js\/client/
    ],
    exclude: [
      /node_modules/,
      /thirdparty/
    ]
  }

我希望 webpack 不会解析这两个目录中的任何一个下的任何文件夹,但是我收到了库的错误.例如:

My hope was that webpack wouldn't parse any folders under either of those two directories, but I'm getting errors for libraries that are. For instance:

WARNING in ./~/durandal/js/system.js
51:8-15 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

WARNING in ./~/durandal/js/system.js
52:8-15 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

ERROR in ./~/durandal/js/system.js
Cannot statically analyse 'require(..., ...)' in line 278
 @ ./src/js/client/lib/durandal/overrides/views.js 2:0-37
 @ ./src/js/client/index.js

我是否误解了包含/排除的功能,或者这是 Webpack 的错误?

Am I misunderstanding the functionality of include/exclude, or is this a bug with Webpack?

推荐答案

规则并不决定 webpack 解析哪些文件,而是仅应用于包含并满足条件的文件.即使你根本没有规则,webpack 仍然会解析你在某处导入的相同文件.

The rules do not decide which files are being parsed by webpack, but instead they are only applied to the files which are included and also satisfy the condition. Even if you had no rule at all, webpack would still parse the same files since you imported them somewhere.

您可以排除模块与 externals 选项.这些外部变量必须以某种方式在运行时出现(例如加载到

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆