marketingsystem_temp_h5/build/webpack.base.js

114 lines
3.5 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 HtmlWebpackPlugin = require("html-webpack-plugin");
const { VantResolver } = require('@vant/auto-import-resolver');
const AutoImport = require('unplugin-auto-import/webpack');
const Components = require('unplugin-vue-components/webpack');
2024-09-05 10:55:42 +08:00
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
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({
2024-09-03 14:07:00 +08:00
ignoreOrder: true, // 解决 css 引入顺序不一导致冲突的警告问题
2024-09-11 16:31:15 +08:00
filename: 'css/[name].[contenthash:8].content.css',
2024-08-23 16:01:52 +08:00
}),
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: [VantResolver()],
dts: path.resolve(__dirname, "../src/auto-imports.d.ts"),
// eslintrc: {
// enabled: true,
// filepath: path.resolve(__dirname, "./.eslintrc-auto-import.json"),
// globalsPropValue: true,
// },
}),
Components({
resolvers: [VantResolver()],
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, // 不从代码中提取注释
}),
2024-09-05 10:55:42 +08:00
new CssMinimizerPlugin(),
2024-08-23 16:01:52 +08:00
],
},
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: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
2024-08-23 16:01:52 +08:00
alias: {
'@': path.join(__dirname, '../src')
}
},
cache: {
type: 'filesystem', // 使用文件缓存
},
}