marketingsystem_temp_h5/build/webpack.com.js

81 lines
2.4 KiB
JavaScript
Raw Normal View History

2024-08-23 16:01:52 +08:00
const path = require("path");
const { VueLoaderPlugin } = require("vue-loader");
2024-08-23 16:01:52 +08:00
const TerserPlugin = require("terser-webpack-plugin");
2024-09-12 11:35:58 +08:00
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const { VantResolver } = require('@vant/auto-import-resolver');
const AutoImport = require('unplugin-auto-import/webpack');
const Components = require('unplugin-vue-components/webpack');
2024-08-23 16:01:52 +08:00
module.exports = {
mode: 'production', // 生产模式,会开启 tree-shaking 和 压缩代码,以及其他优化
2024-08-23 17:19:10 +08:00
entry: { // 后续需要上传哪个组件单独配置入口,其余注释
2024-09-20 14:14:41 +08:00
list: '@/views/templates/cmsList/index.ts',
detail: '@/views/templates/cmsDetail/index.ts',
cmsLJJConfig: '@/views/templates/cmsLJJConfig/index.ts',
2024-08-23 16:01:52 +08:00
// ...
},
output: {
path: path.join(__dirname, '../dist'),
filename: '[name]/[name]_com.[chunkhash:8].chunk.js',
library: {
name: 'TempCom',
type: 'umd', // 使用 UMD 模式以支持多种引入方式
},
publicPath: '/',
clean: true,
},
module: {
rules: [
{
test: /\.vue$/,
2024-08-26 10:47:30 +08:00
exclude: /node_modules/,
use: ['thread-loader', 'vue-loader'],
2024-08-23 16:01:52 +08:00
},
{
test: /\.(js|ts)$/,
2024-08-26 10:47:30 +08:00
exclude: /node_modules/,
2024-08-23 16:01:52 +08:00
use: ['thread-loader', 'babel-loader'],
},
{
2024-08-26 10:47:30 +08:00
test: /\.css$/,
use: ['vue-style-loader', 'css-loader'],
2024-08-23 16:01:52 +08:00
},
2024-08-26 10:47:30 +08:00
{
test: /\.scss$/,
use: ['vue-style-loader', 'css-loader', 'sass-loader']
}
2024-08-23 16:01:52 +08:00
]
},
plugins: [
new VueLoaderPlugin(), // vue-loader 插件
2024-09-12 11:35:58 +08:00
// new BundleAnalyzerPlugin(),
AutoImport({ resolvers: [VantResolver()] }),
Components({ resolvers: [VantResolver()] }),
2024-08-23 16:01:52 +08:00
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
2024-11-01 11:58:46 +08:00
drop_console: true, // 移除所有的`console`语句
2024-08-23 16:01:52 +08:00
},
output: {
comments: false, // 去掉注释
},
},
extractComments: false, // 不从代码中提取注释
}),
],
},
resolve: {
2024-09-11 16:31:15 +08:00
// 如果用的是pnpm 不要配置这个,会有幽灵依赖的问题,访问不到很多模块
2024-08-23 16:01:52 +08:00
// 查找第三方模块只在本项目的node_modules中查找
modules: [path.resolve(__dirname, '../node_modules')],
2024-11-01 11:58:46 +08:00
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
alias: {
2024-08-23 16:01:52 +08:00
'@': path.join(__dirname, '../src')
}
},
}