In 6.x `globOptions.ignore` doesn't act like `ignore` from 5.x
msbit opened this issue · 9 comments
- Operating System: macOS 10.13.6
- Node Version: v14.5.0
- NPM Version: 6.14.7
- webpack Version: 4.44.1
- copy-webpack-plugin Version: 6.0.3
I've just moved from ~5.1.0
to ~6.0.0
and migrated my configuration webpack configuration to match, but the files that were previously successfully ignored are now being copied to the destination. I have seen a similar issue (#498) which was closed but with a request to reopen as another issue, so this might fit the bill.
Arguments to new CopyWebpackPlugin
have changed from:
[
{
from: 'secret',
ignore: ['*.example']
},
{
from: 'static'
}
]
to:
{
patterns: [
{
from: 'secret',
globOptions: {
ignore: ['*.example']
}
},
{
from: 'static'
}
]
}
Expected Behavior
I'd expect that the attached configuration would stop *.example
files from the secret
directory being copied to the destination.
Actual Behavior
The example file is being copied to dist
:
$ find secret dist -name '*.example'
secret/Configuration.json.example
dist/Configuration.json.example
Code
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env', {
targets: 'last 2 versions'
}
]
],
plugins: [
'@babel/plugin-transform-runtime',
'babel-plugin-root-import'
]
}
}
}
]
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: 'secret',
globOptions: {
ignore: ['*.example']
}
},
{
from: 'static'
}
]
})
]
};
I've created a repo to show the issue (https://github.com/msbit/copy-webpack-plugin-ignore-issue).
There are two branches, one for 5.1.1 (https://github.com/msbit/copy-webpack-plugin-ignore-issue/tree/copy-webpack-plugin-5.1.1) and one for 6.0.3 (https://github.com/msbit/copy-webpack-plugin-ignore-issue/tree/copy-webpack-plugin-6.0.3).
Switching to each then running npm install
and npm test
you get the following:
copy-webpack-plugin-5.1.1
Hash: a5b950643da5d73067a9
Version: webpack 4.44.1
Time: 95ms
Built at: 12/08/2020 11:38:17 pm
Asset Size Chunks Chunk Names
foo 0 bytes [emitted]
main.js 930 bytes 0 [emitted] main
Entrypoint main = main.js
[0] ./src/index.js 0 bytes {0} [built]
copy-webpack-plugin-6.0.3
Hash: a5b950643da5d73067a9
Version: webpack 4.44.1
Time: 106ms
Built at: 12/08/2020 11:39:05 pm
Asset Size Chunks Chunk Names
bar.example 0 bytes [emitted]
foo 0 bytes [emitted]
main.js 930 bytes 0 [emitted] main
Entrypoint main = main.js
[0] ./src/index.js 0 bytes {0} [built]
Because we start to send absolute path to globby, I think we can fix it, feel free to send a PR
@evilebottnawi it could be upstream, I've been looking through it; globby
simply passes it on to fast-glob
which is possibly dropping the ball.
I've raised an issue against fast-glob
(mrmlnc/fast-glob#285)
Looks like you are right, problem on fast-glob
side
I bumped into the same thing while upgrading from v5 to v6, I ended up prefixing my ignore patterns with double-asterisks, so ['js/**', 'build/**']
became ['**/js/**', '**/build/**
]`. I saw that somewhere but can't find the reference now.
Works as expected mrmlnc/fast-glob#285 (comment), can't be fixed in our side, sorry
Hey @evilebottnawi, I understand that you don't want to have both globby
processing the ignored patterns and doing so in this module, but it's not fair to say that copy-webpack-plugin
works as expected (per se), and that this can't be fixed here.
fast-glob works as expected, as it's a reimplementation of glob, but copy-webpack-plugin
(prior to 0be6470) would iterate over the ignore
patterns provided, using minimatch
to determine whether the paths returned matched any of these patterns and discard them if so.
@msbit I understand you, but reintroducing minimatch
again for ignored will reduce performance, we removed it because as it affected performance (5%-50% slow) and rely on the built-in implementation, if you want to return old behavior you can use the filter
option, and implement any complex logic
Thanks @evilebottnawi, I let my frustrations get a hold of my there. I'll take a look at the filter
option and see if that can address my situation.