I'm working with copy files from /src/libs/** to /dist directory using webpack,My config of copyWebpackPlugin is
new copyWebpackPlugin([{
from: __dirname + '/src/libs/**',
to: __dirname + '/dist'
}])
but It will generate an extra src folder in dist.I expect my target folder will be /dist/copy-files
but it's /dist/src/copy-files
.Is there any solutions?
You have to differentiate between context
and from
.
context
is the root path for the source files, and will not be added to the target paths.from
: The paths determined by the from
glob, however, will be added to the target paths.So in your case, try
new copyWebpackPlugin([{
context: __dirname + '/src',
from: 'libs/**',
to: __dirname + '/dist'
}])
instead.
If you use an absolute path in to
, copy-webpack-plugin will add the resolved from
to it.
To get what you want, just name the directory.
new copyWebpackPlugin([{
from: __dirname + '/src/libs/**',
to: 'dist'
}])
The from
path also doesn't need to be absolute. It won't change the result, but still maybe a bit cleaner.
new copyWebpackPlugin([{
from: 'src/libs/**',
to: 'dist'
}])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With