使用 Babel + webpack 排除静态 JS 文件进行编译

Excluding static JS files for compilation with Babel + webpack

我在我的新项目中使用 webpackBabel。在添加静态 JS 文件之前,一切都很好。通常捆绑操作需要 5 秒。但是在添加 OpenLayers 之后,库捆绑大约需要 420 秒!!! OpenLayers JS 文件大小约为 490 KB,并且已被丑化。所以它不需要编译。

我在没有使用 Babel 的情况下仅使用 webpack 进行了测试,耗时 5 秒。所以问题是关于 Babel 编译的。我怎样才能防止 Babel 不编译 OpenLayers 并将其添加到结果包文件中。我也可以使用其他外部 JS 文件以及 OpenLayers。

您可以排除它:

{
  // ...
  loader: 'babel-loader',
  exclude: /node_modules/ // exclude all package you install
}

您可以在 https://webpack.js.org/configuration/module/#rule-exclude

中阅读更多相关信息