I have to use a non open source pub/sub library for websockets (diffusion) and have to stick to a specific version because it's what is used on the server side and I have no control about it.
The issue is that in one single util in their code base they use the reserved keyword interface
and that triggers a minification error that breaks the build:
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
Which regex can I use to exclude this dependency from minification?
config.optimization.minimizer[0].options.exclude = /node_modules/;
does not ecxlude it from minification.
config.optimization.minimizer[0].options.exclude = /^.*(node_modules|.js).*$/;
works but it's too broad
For more context, this is the code of the dependency that is causing the minification to fail:
node_modules/diffusion/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));
});
This is how the webpack config file looks like before my overrides: (we are not allowed to eject)
"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": {
}
}
],
This has been fixed as of version 6.0.0
来源:https://stackoverflow.com/questions/53700102/regex-to-exclude-npm-library-from-minification