1.在根目录创建一个pages文件夹,再在pages文件夹里面创建模块,如下图所示
2.再到webpack.config.js中配置js打包模块的入口和打包后的资源存放路径
entry:{
// 配置多个入口
index:"./pages/index/index.js",
login:"./pages/login/index.js",
person:"./pages/person/index.js",
},
output: {
path: path.join(__dirname, 'dist'),//打包文件存放路径__dirname + "/public",
// publicPath: '/dist/', //公共路径
filename: "[name].bundle.js"//打包后的文件名字
},
3.用html-webpack-plugin插件配置html打包路径等
安装html-webpack-plugin插件:cnpm install html-webpack-plugin -D
webpack.config.js中写入html-webpack-plugin配置,如下
// 引入path 模块
var path = require('path');
// 引入html-webpack-plugin插件
var HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
devtool