copy-webpack-plugin: globOptions.ignore not work expected
Bug report
When I use Copy Plugin follow README, it does not work like README said. And I check issues, after use someone’s method, it work, but not work well in sometimes;
Actual Behavior
I use Copy Plugin to copy dir public
in my project root dir to webpack output path’s dir public
,
And I follow the config in README’s globOptions descriptionn
new CopyWebpackPlugin({
patterns: [
{
from: "public/**/*",
globOptions: {
ignore: [
"**/.DS_Store",
"**/index.html",
"**/asdasd.md",
],
},
},
],
})
it doesn’t work at all. plugin will copy all the files in public;
and after search I found here ignoring-files in Readme.
new CopyWebpackPlugin({
patterns: [
{
from: path.posix.join(
path.resolve(__dirname, "public").replace(/\\/g, "/"), "**/*"),
globOptions: {
ignore: [
"**/.DS_Store",
"**/index.html",
"**/asdasd.md",
],
},
},
],
})
but it doesn’t work, still copy all files.
and I found something in issues, try #498 said that I add path.posix function to ignore
property, it work, but only work on one file…
if I specific more than one file use path.posix, it throw error
new CopyWebpackPlugin({
patterns: [
{
from: "public/**/*",
globOptions: {
ignore: [
"**/.DS_Store",
path.posix.join(__dirname, "public/index.html"),
// path.posix.join(__dirname, "public/asdasd.md"), //if open this. will throw following error
// `ERROR in unable to locate '/project-root-dir/public/**/*' glob`
],
},
},
],
}),
Expected Behavior
It should ignore public/index.html and public/asdasd.md files when copy to webpack output folder.
How Do We Reproduce?
I create a demo repo.
just run pnpm install && pnpm run build
OR npm install && npm run build
.
Please paste the results of npx webpack-cli info
here, and mention other relevant information
System: OS: macOS 12.3.1 CPU: (8) x64 Intel® Core™ i7-7700HQ CPU @ 2.80GHz Memory: 38.72 MB / 16.00 GB Binaries: Node: 18.1.0 - ~/.nvs/default/bin/node Yarn: 1.22.18 - /usr/local/bin/yarn npm: 8.8.0 - ~/.nvs/default/bin/npm Browsers: Chrome: 100.0.4896.127 Firefox: 100.0 Safari: 15.4 Packages: copy-webpack-plugin: ^10.2.4 => 10.2.4 webpack: ^5.72.0 => 5.72.0 webpack-cli: ^4.9.2 => 4.9.2
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 22 (7 by maintainers)
it’s work for me. just add globalOptions-ignore
[**/*.html]
,my webpack.common.js
It means globby can’t find directory
Try to experiment, ignore is working, just with some limitations