Regex将npm库从缩小中排除



我必须为websockets(diffusion(使用一个非开源的pub/sub库,并且必须坚持使用特定的版本,因为它是服务器端使用的,我无法控制它。

问题是,在他们代码库中的一个util中,他们使用了保留关键字interface,这会触发一个破坏构建的缩小错误:

Failed to minify the code from this file: 
./node_modules/babel-loader/lib??ref--6-oneOf-2!./node_modules/diffusion/src/node_modules/util/interface.js:127 
Read more here: bit.ly/CRA-build-minify

我可以使用哪个正则表达式将此依赖项从缩小中排除

config.optimization.minimizer[0].options.exclude = /node_modules/;不会阻止其缩小。

config.optimization.minimizer[0].options.exclude = /^.*(node_modules|.js).*$/;有效,但太宽


对于更多上下文,这是导致缩小失败的依赖项的代码:

node_modules/didiffusion/src/node_modules/util/interface.js

function _implements() {
var args = Array.prototype.slice.call(arguments, 0);
var impl = args.pop();
var unsatisfied = [];
...
// The joys of duck type. Quack quack
args.forEach(function(interface) {          <<<<<<<<<<<<<<<<<<<<<
unsatisfied = unsatisfied.concat(interface(impl));
});

这就是我重写之前的webpack配置文件的样子:(我们不允许弹出(

"optimization": {
"minimizer": [
{
"options": {
"test": {
},
"extractComments": false,
"sourceMap": true,
"cache": true,
"parallel": true,
"terserOptions": {
"output": {
"ecma": 5,
"comments": false,
"ascii_only": true
},
"parse": {
"ecma": 8
},
"compress": {
"ecma": 5,
"warnings": false,
"comparisons": false,
"inline": 2
},
"mangle": {
"safari10": true
}
}
}
},
{
"pluginDescriptor": {
"name": "OptimizeCssAssetsWebpackPlugin"
},
"options": {
"assetProcessors": [
{
"phase": "compilation.optimize-chunk-assets",
"regExp": {
}
}
],

自版本6.0.0 起,此问题已得到修复

不弹出IMO.时更容易修复

您可能正在使用旧版本或react脚本,只需将其升级到react-scripts@>=2.0.0即可。

摘自React文档的本节

最新更新