I have an app in which I'm using Webpack. In this app, I need to copy some static .html files from various directories in my source
directory to the same hierarchy in the public
directory. In an attempt to do this, I'm using the CopyWebpackPlugin. At this time, my webpack.config.js file looks like this:
webpack.config.js
const path = require('path');
const projectRoot = path.resolve(__dirname, '../');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: {
app: './source/index.html.js',
},
output: {
path: path.resolve(__dirname, 'public'),
filename: '[name].package.js'
},
module: {
rules: [
{
test: /\.css$/,
loaders: ['style-loader','css-loader']
},
]
},
plugins: [
new CopyWebpackPlugin(
[ { from: './source/**/*.html', to: './public', force:true } ],
{ copyUnmodified: true }
)
]
};
When I run webpack
from the command line, everything works as I want. The HTML files are successfully copied, including their directories, into the public
directory. However, when copied, the source directory name is included. For example, if my directory structure is like this:
/source
/dir-1
/child-a
index.html
page.html
/child-b
index.html
contact.html
/dir-2
index.html
I'm expecting the result of CopyWebpackPlugin
to output to the following:
expected:
/public
/dir-1
/child-a
index.html
page.html
/child-b
index.html
contact.html
/dir-2
index.html
However, what I'm actually getting is:
actual:
/public
/source
/dir-1
/child-a
index.html
page.html
/child-b
index.html
contact.html
/dir-2
index.html
Notice how the source
directory is included in the copy target. I don't understand why this is being included. More importantly, I need to remove it. How do I remove the source
directory from the path in the target?