forked from zhizouvip/ok-admin-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
81 lines (77 loc) · 2.5 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
76
77
78
79
80
81
import type { UserConfig, ConfigEnv } from 'vite'
import { loadEnv, defineConfig } from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
/** eslint效验插件 https://eslint.vuejs.org/rules/ */
import vitePluginEslint from 'vite-plugin-eslint'
/** 打包分析插件: https://www.npmjs.com/package/rollup-plugin-visualizer */
import { visualizer } from 'rollup-plugin-visualizer'
/** 打包生成gzip: https://www.npmjs.com/package/vite-plugin-compression */
import viteCompression from 'vite-plugin-compression'
/** 将外部导入转换为全局变量,打包把模块排除 */
// import externalGlobals from 'rollup-plugin-external-globals'
// https://cn.vitejs.dev/config/#build-assetsdir
// https://vitejs.dev/config/
// https://www.vitejs.net/guide/build.html#公共基础路径
// Dotenv 是一个零依赖的模块,它能将环境变量中的变量从 .env 文件加载到 process.env 中
// const dotenv = require("dotenv")
function pathResolve(dir: string) {
return path.resolve(process.cwd(), '.', dir)
}
export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd()
const env = loadEnv(mode, root)
return {
plugins: [
vue(),
vitePluginEslint({
cache: false // 禁用eslint缓存
}),
vueJsx(),
visualizer(),
viteCompression({
/** @name 文件超过4kb则进行压缩 */
threshold: 4096,
/** @name 压缩算法:'gzip','brotliCompress' ,'deflate','deflateRaw' */
algorithm: 'gzip',
/** @name 压缩文件后缀名 */
ext: 'gzip'
})
],
base: env['VITE_PUBLIC_PATH'] || '/',
resolve: {
alias: {
'@': path.resolve(__dirname, 'src')
}
},
server: {
port: 3000,
host: '0.0.0.0'
},
build: {
outDir: env['VITE_OUT_DIR'] || 'dist'
// 将外部导入转换为全局变量,打包把模块排除
// rollupOptions: {
// external: ['vue', 'pinia', 'vue-router', 'axios'],
// plugins: [
// externalGlobals({
// vue: 'Vue',
// pinia: 'Pinia',,
// 'vue-router': 'VueRouter',
// axios: 'axios'
// })
// ]
// }
}
// 全局scss变量,混入
/* css: {
preprocessorOptions: {
scss: {
additionalData:
'@import "./src/assets/css/variables.scss";' + '@import "./src/assets/css/mixins.scss";'
}
}
} */
}
})