forked from Minori-ty/vite-js-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
142 lines (137 loc) · 4.1 KB
/
vite.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import viteCompression from 'vite-plugin-compression'
import viteImagemin from 'vite-plugin-imagemin'
import importToCDN from 'vite-plugin-cdn-import'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
base: '/',
resolve: {
alias: {
'/images': 'src/assets/images',
styles: resolve(__dirname, 'src/styles'),
router: resolve(__dirname, 'src/router'),
views: resolve(__dirname, 'src/views'),
components: resolve(__dirname, 'src/components'),
data: resolve(__dirname, 'src/data'),
utils: resolve(__dirname, 'src/utils'),
src: resolve(__dirname, 'src'),
assets: resolve(__dirname, 'src/assets'),
mobile: resolve(__dirname, 'src/views/Mobile'),
PC: resolve(__dirname, 'src/views/PC'),
'/pic': 'src/assets/images/pic',
},
},
plugins: [
vue(),
viteCompression({
//生成压缩包gz
verbose: true,
disable: false,
threshold: 10240,
algorithm: 'gzip',
ext: '.gz',
}),
// 配置CDN
importToCDN({
modules: [
{
name: 'vue',
var: 'Vue',
path: 'https://unpkg.com/vue@next',
},
{
name: 'element-plus',
var: 'ElementPlus',
path: `https://unpkg.com/element-plus`,
css: 'https://unpkg.com/element-plus/dist/index.css',
},
],
}),
viteImagemin({
gifsicle: {
optimizationLevel: 7,
interlaced: false,
},
optipng: {
optimizationLevel: 7,
},
mozjpeg: {
quality: 50,
},
pngquant: {
quality: [0.8, 0.9],
speed: 4,
},
svgo: {
plugins: [
{
name: 'removeViewBox',
},
{
name: 'removeEmptyAttrs',
active: false,
},
],
},
}),
],
// 引入全局scss文件
css: {
preprocessorOptions: {
// scss: {
// additionalData: '@import "./src/styles/variables";',
// },
//消除element-plus警告
postcss: {
plugins: [
{
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: atRule => {
if (atRule.name === 'charset') {
atRule.remove()
}
},
},
},
],
},
},
},
build: {
terserOptions: {
compress: {
//生产环境时移除console
drop_console: true,
drop_debugger: true,
},
},
// 取消计算文件大小,加快打包速度
reportCompressedSize: false,
sourcemap: true,
// assetsDir: 'static/img',
rollupOptions: {
output: {
chunkFileNames: 'js/[name]-[hash].js',
entryFileNames: 'js/[name]-[hash].js',
assetFileNames: '[ext]/[name]-[hash].[ext]',
},
},
},
server: {
// host: '0.0.0.0',
port: 3001,
},
})
// package.json:
// "gitHooks": {
// "pre-push": "lint-staged"
// },
// "lint-staged": {
// "*.{js,vue}": "eslint",
// "src/**/*.{vue,css,less}": "stylelint"
// },