我将我的项目与webpack捆绑在一起。我想在两个单独的html文件中将一个javascript文件捆绑两次。如何实现?
我的文件夹结构如下
dist
|- index1.html
|- index2.html
|- js
|- index1.bundle.js
|- index2.bundle.js
webpack.config.js
这是webpack.config.js
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
index: './src/js/index.js',
index2: './src/js/index2.js'
},
output: {
filename: './js/[name].bundle.js'
},
watch: true,
plugins: [
new HtmlWebpackPlugin({
hash: true,
template: './src/index.html',
filename: './index.html'
}),
new HtmlWebpackPlugin({
hash: true,
template: './src/index2.html',
filename: './index2.html'
})
]
};
如何将同一文件捆绑在两个单独的html文件中?
答案 0 :(得分:0)
已经弄清楚了。我要做的就是分块。
我必须添加
块:第一个htmlwebpackplugin和[p>
块:第二个htmlwebpackplugin的['index2']
更新了webpack.config.js
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
index: './src/js/index.js',
index2: './src/js/index2.js'
},
output: {
filename: './js/[name].bundle.js'
},
watch: true,
plugins: [
new HtmlWebpackPlugin({
hash: true,
template: './src/index.html',
filename: './index.html',
chunks: ['index']
}),
new HtmlWebpackPlugin({
hash: true,
template: './src/index2.html',
filename: './index2.html',
chunks: ['index2']
})
]
};