环境
创建项目
- 初始化文件夹
npm init -y - 配置指定版本依赖
- 安装依赖
npm i - 配置启动命令
"dev": "webpack-dev-server --open --port 5500 --hot --host 127.0.0.1"
1 配置
npm init -y
2 配置package.json文件

{
"name": "base",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack-dev-server --open --port 5500 --hot --host 127.0.0.1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"html-webpack-plugin": "^4.5.0",
"webpack": "^4.17.1",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.2",
"webpack-hot-middleware": "^2.22.0",
"webpack-merge": "^4.1.1"
}
}
2 安装依赖
cnpm i
3 创建文件

4 配置webpack.config.js

const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path')
const html = new HtmlWebpackPlugin({
template: path.join( __dirname, './src/index.html' ),
filename:'index.html'
})
module.exports = {
mode: "development",
plugins:[
html
]
}
5启动项目
cnpm i
npm run dev
