1、准备
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> hahaha </body></html>
function add(x, y) { return x + y;}console.log(add(1, 2));console.log(add(2, 2));
2、webpack.config.js
const { resolve } = require('path');const HtmlWebpackPlugin = require('html-webpack-plugin');module.exports = { entry: './src/index.js', output: { filename: 'built.js', path: resolve(__dirname, 'build') }, module: { }, plugins: [ new HtmlWebpackPlugin({ template: './src/index.html' }) ], mode: 'development', // 用来自动化(自动编译,自动打开浏览器,自动刷新浏览器~~) // 特点:只会在内存中编译打包,不会有任何输出 // 启动devServer指令为:npx webpack-dev-server devServer: { // 启动gzip压缩 compress: true, // 端口号 port: 3000, // 自动打开浏览器 open: true, //自动刷新 liveReload:true, // HMR true开启 HMR 功能 开启模块热替换功能后将在不刷新整个页面的情况下通过用新模块替换老模块来做到实时预览 hot:false }};
3、结果

