-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
115 lines (114 loc) · 2.84 KB
/
webpack.config.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const UnpluginAutoImportPlugin = require('unplugin-auto-import/webpack')
const DotenvWebpackPlugin = require('dotenv-webpack')
const webpack = require('webpack')
const path = require('path')
module.exports = {
// 关闭log
stats: {
// logging: 'none',
// warnings: false,
// errors: false,
// modules: false,
// entrypoints: false,
// children: false,
// assets: false
},
mode: 'production',
entry: './src/main.ts',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
clean: true
},
resolve: {
extensions: ['.ts', '.js', '.jsx', '.tsx', '.vue', '.json'],
alias: {
'@': path.resolve(__dirname, 'src')
}
},
plugins: [
new webpack.DefinePlugin({
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: false
}),
new webpack.ProvidePlugin({
process: 'process/browser'
}),
new HtmlWebpackPlugin({
template: './src/index.html',
isBrowser: false,
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
}
}),
new ForkTsCheckerWebpackPlugin(),
new VueLoaderPlugin(),
UnpluginAutoImportPlugin({
imports: ['vue'],
dts: 'src/auto-imports.d.ts',
eslintrc: {
enabled: true, // Default `false`
filepath: '.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
}
}),
new DotenvWebpackPlugin({
// prefix: 'import.meta.env.',
path: './.env.production',
allowEmptyValues: true,
systemvars: true,
silent: true
})
],
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
// 匹配以.css结尾的文件
test: /\.css$/,
// 使用css-loader和style-loader去解析
use: ['style-loader', 'css-loader']
},
{
test: /\.(less)$/,
use: ['style-loader', 'css-loader', 'less-loader']
},
{
test: /\.(js|ts|tsx|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader'
},
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
appendTsxSuffixTo: [/\.vue$/],
transpileOnly: true
}
}
]
},
{
test: /\.(png|jpg|gif|jpeg|svg)$/,
use: [
{
loader: 'file-loader',
options: {
esModule: false
}
}
]
}
]
}
}