では動作しませんHtmlWebpackPlugin:WDSはバック
/dist
--some.html
--some.css
--some.js
--another.html
--another.css
--another.js
/src
--...
webpack.config.babel.js
すべてがOKですが、構造がある場合:htmlファイルで
/dist
--/public
----some.css
----some.js
----another.css
----another.js
--some.html
--another.html
/src
--...
webpack.config.babel.js
変更は、後に手動でも反映されていませんページをリロードします。
最初のディレクトリ構造のケースのための私の堅牢な設定:
...
module.exports = {
entry: {
index: './src/index/index',
contacts: './src/contacts/contacts',
about: './src/about/about',
},
output: {
path: path.join(__dirname, "dist"),
publicPath: "/",
filename: "[name].js",
library: "[name]"
},
resolve: {
extensions: ['.js', '.css', '.scss'],
},
resolveLoader: {
modules: ['node_modules'],
extensions: ['.js']
},
module: {
rules: [
{ test: /\.html$/, loader: "html-loader" },
{ test: /\.js$/, loader: "babel-loader", exclude: /node_modules/},
{ test: /\.css$/, loader: ExtractTextPlugin.extract({ fallback: "style-loader", use: "css-loader" }) },
},
plugins: [
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(NODE_ENV),
}),
new ExtractTextPlugin("[name].css"),
]
};
if (NODE_ENV == 'development') {
let htmlPlugins = [];
for(let entry in module.exports.entry) {
htmlPlugins.push(
new HtmlWebpackPlugin({
chunks: [`${entry}`],
filename: `${entry}.html`,
template: `${module.exports.entry[entry]}.html`,
})
);
}
module.exports.plugins = (module.exports.plugins || []).concat(htmlPlugins);
}
そして最後のケースのための設定:あなたが最後のケースのHtmlWebpackPluginファイル名に見ることができるように
...
module.exports = {
entry: {
index: './src/index/index',
contacts: './src/contacts/contacts',
about: './src/about/about',
},
output: {
path: path.join(__dirname, "dist/public/"),
publicPath: "/public/",
filename: "[name].js",
library: "[name]"
},
resolve: {
extensions: ['.js', '.css', '.scss'],
},
resolveLoader: {
modules: ['node_modules'],
extensions: ['.js']
},
module: {
rules: [
{ test: /\.html$/, loader: "html-loader" },
{ test: /\.js$/, loader: "babel-loader", exclude: /node_modules/},
{ test: /\.css$/, loader: ExtractTextPlugin.extract({ fallback: "style-loader", use: "css-loader" }) },
},
plugins: [
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(NODE_ENV),
}),
new ExtractTextPlugin("[name].css"),
]
};
if (NODE_ENV == 'development') {
let htmlPlugins = [];
for(let entry in module.exports.entry) {
htmlPlugins.push(
new HtmlWebpackPlugin({
chunks: [`${entry}`],
filename: `../${entry}.html`,
template: `${module.exports.entry[entry]}.html`,
})
);
}
module.exports.plugins = (module.exports.plugins || []).concat(htmlPlugins);
}
ディレクトリback(../${entry}.html
、)を含む。
ありがとうございました!私のためにはうまくいく。 –