-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
109 lines (106 loc) · 3.34 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
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
import { loadEnv, defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import UnoCSS from 'unocss/vite'
// import autoprefixer from 'autoprefixer'
// import UnoCssPostcss from '@unocss/postcss'
import { createHtmlPlugin } from 'vite-plugin-html'
import AutoImport from 'unplugin-auto-import/vite'
// import Components from 'unplugin-vue-components/vite'
import Components from '@uni-helper/vite-plugin-uni-components'
import path from 'path'
const INVALID_CHAR_REGEX = /[\u0000-\u001F"#$&*+,:;<=>?[\]^`{|}\u007F]/g
const DRIVE_LETTER_REGEX = /^[a-z]:/i
// @ts-ignore
export default ({ mode, command }) => {
console.log('mode', mode)
// const envDir = process.cwd()
const envDir = path.resolve(process.cwd(), 'env')
const env = loadEnv(mode, envDir)
console.log('env', env)
return defineConfig({
define: {
__APP_TITLE__: JSON.stringify(env.VITE_APP_TITLE),
__DYNAMIC_MENU__: env.VITE_DYNAMIC_MENU
},
envDir,
build: {
outDir: env.VITE_OUTDIR || 'dist',
rollupOptions: {
output: {
// https://github.com/rollup/rollup/blob/master/src/utils/sanitizeFileName.ts
sanitizeFileName(name) {
const match = DRIVE_LETTER_REGEX.exec(name)
const driveLetter = match ? match[0] : ''
// A `:` is only allowed as part of a windows drive letter (ex: C:\foo)
// Otherwise, avoid them because they can refer to NTFS alternate data streams.
return driveLetter + name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, '')
}
}
}
},
css: {
postcss: {
plugins: [
// UnoCssPostcss({}),
// autoprefixer({
// overrideBrowserslist: ['Android >= 4', 'ios >= 8'],
// remove: process.env.UNI_PLATFORM !== 'h5'
// })
// require('@unocss/postcss')({}),
// require('autoprefixer')({
// overrideBrowserslist: ['Android >= 4', 'ios >= 8'],
// remove: process.env.UNI_PLATFORM !== 'h5'
// })
]
},
preprocessorOptions: {
scss: {
javascriptEnabled: true,
additionalData: `@import "@packages/styles/theme.scss";`
}
}
},
plugins: [
AutoImport({
imports: ['vue', 'vue-router'],
dts: false
}),
Components({
resolvers: []
}),
UnoCSS(),
uni(),
createHtmlPlugin({
inject: {
data: {
// title: env.VITE_APP_TITLE
// injectScript: `<script src="./inject.js"></script>`
}
}
})
],
base: env.VITE_APP_BASE || '/',
resolve: {
// preserveSymlinks: true,
alias: {
'@': path.resolve(__dirname, 'src'),
// vue: 'vue/dist/vue.esm-bundler.js',
'@packages': path.resolve(__dirname, 'src/packages')
},
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.vue', '.json', '.less', '.scss', '.css']
},
esbuild: {
drop: mode === 'production' && command === 'build' ? ['console', 'debugger'] : []
},
server: {
proxy: {
// [env.VITE_API_URL]: {
// target: env.VITE_PROXY_TARGET,
// changeOrigin: true,
// secure: false
// // rewrite: path => path.replace(new RegExp(`^${env.VITE_API_URL}`), '')
// }
}
}
})
}