ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
1. 命令行运行 `npm install webpack-dev-server html-webpack-plugin --save-dev` 2. 项目根目录下创建 `index.html` 文件 ``` <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Javascript设计模式</title> </head> <body> <p>Javascript设计模式</p> </body> </html> ``` 3. 修改 `webpack.dev.config.js` ``` const path = require('path') const HtmlWebpackPlugin = require('html-webpack-plugin') module.exports = { entry: './src/index.js', output: { path: __dirname, filename: './release/bundle.js' }, plugin: [ new HtmlWebpackPlugin({ template: './index.html' }) ], devServer: { contentBase: path.join(__dirname, './release'), // 根目录 open: true, // 自动打开浏览器 port: 9000 } } ``` 4. 修改 `package.json` 中的 `script.dev` 属性 ``` "dev": "webpack-dev-server --config ./webpack.dev.config.js --mode development" ``` 5. 命令行运行 `npm run dev`