1. 新建一个项目
yarn init -y
yarn add webpack webpack-cli -D
yarn add html-webpack-plugin -D
webpack.config.js
let path = require('path');
let HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'development',
entry: {
home: './src/index.js',
other: './src/other.js'
},
output: {
// [name] : 代表home/other
filename: '[name].[hash:8].js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'home.html',
chunks: ['home'] // 引入home.js
}),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'other.html',
chunks: ['other', 'home'] // 引入other.js 和 home.js
}),
],
}
网友评论