-
Notifications
You must be signed in to change notification settings - Fork 87
/
vite.config.js
91 lines (89 loc) · 2.62 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
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import viteCompression from 'vite-plugin-compression'
// eslint
import eslintPlugin from 'vite-plugin-eslint'
// https://vitejs.dev/config/
export default defineConfig(({ command })=> {
return {
plugins: [
vue(),
createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
symbolId: 'icon-[dir]-[name]'
}),
// 自动引入内容
AutoImport({
imports: [
'vue',
'vue-router'
],
dirs: [
'src/hooks/**',
'src/stores/**',
'src/utils/**'
],
resolvers: command === 'build' ? [ElementPlusResolver()] : [],
dts: 'src/auto-import/imports.d.ts',
eslintrc: {
enabled: false
}
}),
// 自动引入组件
Components({
dirs: [
'src/components'
],
resolvers: command === 'build' ? [ElementPlusResolver()] : [],
dts: 'src/auto-import/components.d.ts'
}),
// 对大于 1k 的文件进行压缩
viteCompression({
threshold: 1000,
})
].concat(
// eslint
command !== 'build' ? [eslintPlugin({ include: ['src/**/*.js', 'src/**/*.vue', 'src/*.js', 'src/*.vue'] })] : []
),
server: {
host: true,
port: 9527,
open: true
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
}
},
build: {
base: './',
rollupOptions: {
// 静态资源分类打包
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
// 静态资源分拆打包
manualChunks (id) {
if (id.includes('node_modules')) {
if (id.toString().indexOf('.pnpm/') !== -1) {
return id.toString().split('.pnpm/')[1].split('/')[0].toString();
} else if (id.toString().indexOf('node_modules/') !== -1) {
return id.toString().split('node_modules/')[1].split('/')[0].toString();
}
}
}
}
},
sourcemap: false,
target: 'es2015',
reportCompressedSize: false
}
}
})