forked from surmon-china/surmon-china.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
46 lines (43 loc) · 1.43 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
import path from 'path'
import { defineConfig, Plugin } from 'vite'
import vue from '@vitejs/plugin-vue'
import { CDN_PREFIX } from './src/config'
// https://github.com/vitejs/vite/issues/5071
// https://github.com/vitejs/vite/pull/5535/files
// https://github.com/vitejs/vite/blob/main/packages/plugin-vue/src/main.ts#L102
// https://vue-loader.vuejs.org/zh/options.html#exposefilename
// https://github.com/vitejs/vite/issues/4646#issuecomment-905279744
// https://github.com/TeleworkInc/rollup-plugin-import-meta-url/blob/master/index.js
const resolveMetaUrl = (): Plugin => ({
name: 'resolveMetaUrl',
resolveImportMeta(property, chunk) {
if (property === 'url') {
// MARK: keep 'file://' + '/XXX'
return `'file:///${path.relative(process.cwd(), chunk.moduleId)}'`
}
}
})
// https://github.com/antfu/vite-ssg/issues/156#issuecomment-1047341987
const fixSwiperCSSOnSSR = (): Plugin => ({
name: 'fix-swiper-ssr',
transform(code, id, options = {}) {
if (options.ssr) return code.replace(/import .swiper\/(s?css|less).*$/gm, '')
}
})
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
plugins: [vue(), resolveMetaUrl(), fixSwiperCSSOnSSR()],
base: mode === 'production' ? CDN_PREFIX : '/',
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'@examples': path.resolve(__dirname, 'examples')
}
},
server: {
open: true
},
build: {
cssCodeSplit: false
}
}))