-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
98 lines (96 loc) · 2.48 KB
/
webpack.common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const { VueLoaderPlugin } = require('vue-loader')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const globalVar = require('./config/globalVar')
const path = require('path')
const Dotenv = require('dotenv-webpack')
// EL UI
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.resolve(__dirname, './src/main.js'),
cache: {
type: 'memory'
},
optimization: {
nodeEnv: false
},
resolve: {
extensions: ['.js', '.vue'],
alias: {
'@': path.resolve(__dirname, './src'),
'@views': path.resolve(__dirname, './src/views'),
'@com': path.resolve(__dirname, './com'),
'@serv': path.resolve(__dirname, './service')
}
},
module: {
rules: [
{
test: /\.vue$/,
use: 'vue-loader'
},
{
test: /\.less$/,
use: ['style-loader', 'css-loader', 'less-loader']
},
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|jpg|gif|jpeg|bmp|svg|ico)$/i,
type: 'asset',
generator: {
filename: 'images/[name][ext][query]'
},
parser: {
dataUrlCondition: {
// 如果文件大小小于 limit 参数,就将资源转换成 base64 编码的 DataURL
maxSize: 5120
}
}
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
generator: {
filename: 'fonts/[name][ext][query]'
}
}
]
},
plugins: [
AutoImport({
resolvers: [ElementPlusResolver()]
}),
Components({
resolvers: [ElementPlusResolver()]
}),
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './public/index.html')
}),
new Dotenv({
path: (() => {
if (process.env.NODE_ENV === 'production') {
return path.resolve(__dirname, '.env.production')
} else {
return path.resolve(__dirname, '.env.development')
}
})()
}),
new webpack.DefinePlugin({
__CONFIG__: JSON.stringify(globalVar),
__VUE_OPTIONS_API__: 'true',
__VUE_PROD_DEVTOOLS__: 'false'
}),
new webpack.ProgressPlugin()
]
}