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");
|
2024-08-29 17:32:27 +08:00
|
|
|
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 = {
|
|
|
|
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: {
|
2024-08-28 13:49:34 +08:00
|
|
|
name: 'img/[name].[ext]',
|
|
|
|
esModule: false,
|
2024-08-23 16:01:52 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new VueLoaderPlugin(), // vue-loader 插件
|
|
|
|
new MiniCssExtractPlugin({
|
2024-09-02 18:28:27 +08:00
|
|
|
ignoreOrder: true, // 解决css引入顺序不一导致冲突的警告问题
|
2024-08-23 16:01:52 +08:00
|
|
|
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',
|
|
|
|
// }),
|
2024-08-28 13:49:34 +08:00
|
|
|
AutoImport({
|
|
|
|
imports: ["vue", "vue-router"],
|
|
|
|
dirs: [
|
|
|
|
path.resolve(__dirname, "../src"),
|
|
|
|
],
|
2024-08-29 17:32:27 +08:00
|
|
|
resolvers: [VantResolver()],
|
2024-08-28 13:49:34 +08:00
|
|
|
dts: path.resolve(__dirname, "../src/auto-imports.d.ts"),
|
|
|
|
// eslintrc: {
|
|
|
|
// enabled: true,
|
|
|
|
// filepath: path.resolve(__dirname, "./.eslintrc-auto-import.json"),
|
|
|
|
// globalsPropValue: true,
|
|
|
|
// },
|
|
|
|
}),
|
|
|
|
Components({
|
2024-08-29 17:32:27 +08:00
|
|
|
resolvers: [VantResolver()],
|
2024-08-28 13:49:34 +08:00
|
|
|
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, // 不从代码中提取注释
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
// 如果用的是pnpm 就暂时不要配置这个,会有幽灵依赖的问题,访问不到很多模块
|
|
|
|
// 查找第三方模块只在本项目的node_modules中查找
|
|
|
|
modules: [path.resolve(__dirname, '../node_modules')],
|
2024-08-29 17:32:27 +08:00
|
|
|
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
|
2024-08-23 16:01:52 +08:00
|
|
|
alias: {
|
|
|
|
'@': path.join(__dirname, '../src')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cache: {
|
|
|
|
type: 'filesystem', // 使用文件缓存
|
|
|
|
},
|
|
|
|
}
|