企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
webpack.config.js ``` const { resolve } = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { entry: './src/js/index.js', output: { filename: 'js/built.js', path: resolve(__dirname, 'build') }, plugins: [ new HtmlWebpackPlugin({ template: './src/index.html' }) ], // 生产环境下会自动压缩js代码 mode: 'production' }; ``` src/index.html ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>webpack</title> </head> <body> <h1>hello webpack</h1> </body> </html> ``` src/js/index.js ``` // import '@babel/polyfill'; const add = (x, y) => { return x + y; }; console.log(add(2, 5)); const promise = new Promise(resolve => { setTimeout(() => { console.log('定时器执行完了~'); resolve(); }, 1000); }); console.log(promise); ```