Squ*_*gs. 1 webpack html-webpack-plugin
我正在为项目设置 Webpack,并使用 HTML webpack 插件生成 HTML 文件。
我的问题是生成的 HTML 包含所有捆绑包,而不是特定 HTML 文件的特定入口点。这是我的 ATM 代码
const path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
one: './js/one.js',
two: './js/two.js',
three: './js/three.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: './js/[name].js',
},
module: {
loaders: [],
rules:[
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
},
{
test: /\.(png|jpg|woff|woff2|eot|ttf|svg)$/,
use: ['url-loader?limit=100000&name=./img/[hash].[ext]'],
}
]
},
plugins: [
new HtmlWebpackPlugin({
title: 'One',
template: 'one.ejs', // Load a custom template (ejs by default see the FAQ for details)
filename: 'one.htm'
}),
new HtmlWebpackPlugin({
title: 'Two',
template: 'two.ejs', // Load a custom template (ejs by default see the FAQ for details)
filename: 'two.htm'
}),
new HtmlWebpackPlugin({
title: 'Three',
template: 'three.ejs', // Load a custom template (ejs by default see the FAQ for details)
filename: 'three.htm'
})
]
};
Run Code Online (Sandbox Code Playgroud)
根据文件:
https://webpack.js.org/plugins/html-webpack-plugin/
If you have multiple webpack entry points, they will all be included with script tags in the generated HTML.
Run Code Online (Sandbox Code Playgroud)
有没有办法将 one.js 附加到 one.htm ?两个只对两个.htm?
new HtmlWebpackPlugin({
title: 'One',
chunks: ['one'],
template: 'ejs-render-loader!./one',
filename: 'one'
}),
Run Code Online (Sandbox Code Playgroud)
对于任何谷歌搜索的人,我也刚刚发现你可以使用块来做同样的事情。
| 归档时间: |
|
| 查看次数: |
2112 次 |
| 最近记录: |