marketingsystem_temp_h5/build/webpack.com.js

75 lines
2.0 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");
module.exports = {
mode: 'production', // 生产模式,会开启 tree-shaking 和 压缩代码,以及其他优化
2024-08-23 17:19:10 +08:00
entry: { // 后续需要上传哪个组件单独配置入口,其余注释
2024-08-29 20:22:44 +08:00
list: '@/views/templates/cmsList/index.ts',
detail: '@/views/templates/cmsDetail/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 插件
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
// drop_console: true, // 移除所有的`console`语句
},
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')],
extensions: ['.vue', '.ts', '.js', '.json'],
alias: {
'@': path.join(__dirname, '../src')
}
},
cache: {
type: 'filesystem', // 使用文件缓存
},
}