ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
webpack.config.js ``` const { resolve } = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { entry: './src/index.js', output: { // 文件名称(指定名称+目录) filename: 'js/[name].js', // 输出文件目录(将来所有资源输出的公共目录) path: resolve(__dirname, 'build'), // 所有资源引入公共路径前缀 --> 'imgs/a.jpg' --> '/imgs/a.jpg' publicPath: '/', chunkFilename: 'js/[name]_chunk.js', // 非入口chunk的名称 // library: '[name]', // 整个库向外暴露的变量名 // libraryTarget: 'window' // 变量名添加到哪个上 browser // libraryTarget: 'global' // 变量名添加到哪个上 node // libraryTarget: 'commonjs' }, plugins: [new HtmlWebpackPlugin()], mode: 'development' }; ``` add.js ``` function add(x, y) { return x + y; } export default add; ``` count.js ``` function count(x, y) { return x - y; } export default count; ``` index.js ``` import count from './count'; console.log('index.js文件加载了~'); import('./add').then(({ default: add }) => { console.log(add(1, 2)); }); console.log(count(3, 2)); ```