-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
75 lines (74 loc) · 2.23 KB
/
vite.config.ts
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
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import Unocss from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import Pages from 'vite-plugin-pages'
// https://vitejs.dev/config/
export default defineConfig({
base: './',
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
plugins: [
AutoImport({
dts: 'src/auto-imports.d.ts', // 可以自定义文件生成的位置,默认是根目录下
imports: ['vue', 'vue-router'],
eslintrc: {
enabled: true, // Default `false`
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: 'readonly', // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
},
}),
Components({
// 指定组件位置,默认是src/components
dirs: ['src/components'],
extensions: ['vue'],
// 配置文件生成位置
dts: 'src/components.d.ts',
}),
vue(),
Unocss(),
Pages(),
],
server: {
port: 3000,
open: true, //自动打开
base: './ ', //生产环境路径
},
optimizeDeps: {
include: ['vue', 'vue-router'],
},
css: {
preprocessorOptions: { scss: { charset: false } },
},
// 打包配置
build: {
target: 'modules', // 设置最终构建的浏览器兼容目标。modules:支持原生 ES 模块的浏览器
outDir: 'dist', // 指定输出路径
sourcemap: false, // 构建后是否生成 source map 文件
minify: 'terser', // 混淆器
cssCodeSplit: true, // 启用/禁用 CSS 代码拆分
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
}, // 去除 console debugger
rollupOptions: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[0].toString()
}
},
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
},
}, // 将打包后的资源分开
},
})