marketingsystem_temp_h5/build/webpack.base.js

113 lines
3.4 KiB
JavaScript
Raw Normal View History

2024-08-23 16:01:52 +08:00
const path = require('path')
const { VueLoaderPlugin } = require('vue-loader')
const { DefinePlugin } = require('webpack');
const TerserPlugin = require("terser-webpack-plugin");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
2024-08-23 16:01:52 +08:00
module.exports = {
entry: path.join(__dirname, '../src/main.ts'), // 入口文件
output: {
path: path.join(__dirname, '../dist'),
filename: 'js/[name].[chunkhash:8].chunk.js',
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$/,
2024-08-27 15:05:58 +08:00
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
2024-08-26 10:47:30 +08:00
},
{
test: /\.scss$/,
2024-08-27 15:05:58 +08:00
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader']
2024-08-23 16:01:52 +08:00
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
loader: 'file-loader',
options: {
name: 'img/[name].[ext]',
esModule: false,
2024-08-23 16:01:52 +08:00
},
},
]
},
plugins: [
new VueLoaderPlugin(), // vue-loader 插件
new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash].content.css',
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, '../public/index.html'), // 模板取定义root节点的模板
inject: true, // 自动注入静态资源
title: '营销模版H5',
favicon: path.resolve(__dirname, `../public/favicon.ico`),
}),
// new DefinePlugin({
// __VUE_OPTIONS_API__: 'true',
// __VUE_PROD_DEVTOOLS__: 'false',
// __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
// }),
AutoImport({
imports: ["vue", "vue-router"],
dirs: [
path.resolve(__dirname, "../src"),
],
resolvers: [ElementPlusResolver()],
dts: path.resolve(__dirname, "../src/auto-imports.d.ts"),
// eslintrc: {
// enabled: true,
// filepath: path.resolve(__dirname, "./.eslintrc-auto-import.json"),
// globalsPropValue: true,
// },
}),
Components({
resolvers: [ElementPlusResolver()],
dts: path.resolve(__dirname, "../src/components.d.ts"),
}),
2024-08-23 16:01:52 +08:00
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
// drop_console: true, // 移除所有的`console`语句
},
output: {
comments: false, // 去掉注释
},
},
extractComments: false, // 不从代码中提取注释
}),
new CssMinimizerPlugin(),
],
},
resolve: {
// 如果用的是pnpm 就暂时不要配置这个,会有幽灵依赖的问题,访问不到很多模块
// 查找第三方模块只在本项目的node_modules中查找
modules: [path.resolve(__dirname, '../node_modules')],
extensions: ['.vue', '.ts', '.js', '.json'],
alias: {
'@': path.join(__dirname, '../src')
}
},
cache: {
type: 'filesystem', // 使用文件缓存
},
}