Webpackを使用しているアプリがあります。このアプリでは、source
ディレクトリにあるさまざまなディレクトリの静的な.htmlファイルをpublic
ディレクトリの同じ階層にコピーする必要があります。これを行うには、CopyWebpackPluginを使用しています。この時、私のwebpack.config.jsファイルは次のようになります。Webpack - CopyWebpackPluginを使用してソースからパブリックにファイルをコピーする
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 }
)
]
};
を私はコマンドラインからwebpack
を実行すると、すべてが私が望むように動作します。 HTMLファイルはディレクトリを含めてpublic
ディレクトリに正常にコピーされます。ただし、コピーすると、ソースディレクトリ名が含まれます。例えば、私のディレクトリ構造は次のようである場合:
/source
/dir-1
/child-a
index.html
page.html
/child-b
index.html
contact.html
/dir-2
index.html
私は次のように出力するCopyWebpackPlugin
の結果を期待している:期待
:
/public
/dir-1
/child-a
index.html
page.html
/child-b
index.html
contact.html
/dir-2
index.html
をしかし、どのような私は実際に次のようになっています:
実際:
/public
/source
/dir-1
/child-a
index.html
page.html
/child-b
index.html
contact.html
/dir-2
index.html
コピー先にはsource
ディレクトリが含まれています。なぜこれが含まれているのか分かりません。もっと重要なことに、私はそれを削除する必要があります。ターゲット内のパスからsource
ディレクトリを削除するにはどうすればよいですか?