const path = require('path'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { entry: { // 入口点,即主 JavaScript 文件 app: './src/main.js', }, output: { // 输出文件,捆绑了所有库 filename: '[name]-[contenthash].bundle.js', // 输出包的路径,“dist” 文件夹 path: path.resolve(__dirname, 'dist/test'), // 静态资源文件 assetModuleFilename: "asset-packs/[name]-[hash][ext][query]", }, // 处于生产模式 mode: 'production', // 需要一个源映射 devtool: 'inline-source-map', plugins: [ new HtmlWebpackPlugin({ template: 'src/index.html', // 指定你的HTML模板 filename: 'index.html', // 输出的文件名 inject: 'body', // 将脚本插入到body底部 }), new CleanWebpackPlugin(), new CopyWebpackPlugin({ patterns: [ { from: 'src/favicon.ico', to: '' }, { from: 'src/assets', to: 'assets' } ], }), ], resolve: { extensions: [".tsx", ".ts", ".js"], }, };