119 lines
3.8 KiB
JavaScript
119 lines
3.8 KiB
JavaScript
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')
|
||
|
||
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$/,
|
||
exclude: /node_modules/,
|
||
use: ['thread-loader', 'vue-loader'],
|
||
},
|
||
{
|
||
test: /\.(js|ts)$/,
|
||
exclude: /node_modules/,
|
||
use: ['thread-loader', 'babel-loader'],
|
||
},
|
||
{
|
||
test: /\.css$/,
|
||
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
|
||
},
|
||
{
|
||
test: /\.scss$/,
|
||
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader']
|
||
},
|
||
{
|
||
test: /\.(png|svg|jpg|jpeg|gif)$/i,
|
||
type: 'asset/resource',
|
||
// 使用file-loader或url-loader,选择其一
|
||
// loader: 'file-loader',
|
||
loader: 'file-loader',
|
||
generator:{
|
||
filename: 'static/images/[name].[contenthash:8][ext]'
|
||
},
|
||
options: {
|
||
// 如果使用url-loader,可以设置limit选项来控制是否内联图片
|
||
// limit: 10 * 1024, // 小于10kb的图片会被转成base64格式
|
||
},
|
||
},
|
||
]
|
||
},
|
||
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"),
|
||
// }),
|
||
],
|
||
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', // 使用文件缓存
|
||
},
|
||
} |