ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
#### 快速构建package.json文件 `npm init -y` #### 安装webpack4及其命令行接口 `npm i webpack webpack-cli --save-dev` ``` //package.json文件增加build参数 "scripts": { "build": "webpack" } //webpack.config.js 增加内容 //基于commonjs规范 let path = require('path'); module.exports = { entry:'./src/index.js', output:{ filename:'index.html', path:path.resolve('./dist'), }, module:{}, plugins:[], mode:'development', resolve:{}, } ``` #### webpack 服务器 webpack-dev-server ``` //webpack.config.js 添加内容 devServer:{ contentBase:'./dist', }, ``` #### html-webpack-plugin html打包工具 ``` //https://segmentfault.com/a/1190000013883242 var htmlWebpackPlugin = require('html-webpack-plugin') const path = require('path') module.exports = { entry: './src/script/main.js', output: { filename: 'js/bundle.js', path: path.resolve(__dirname, 'dist') }, plugins: [ new htmlWebpackPlugin({ filename: 'index.html', template: 'index.html', inject: 'head' }) ] } ```