-
Notifications
You must be signed in to change notification settings - Fork 116
/
vite.config.ts
66 lines (63 loc) · 2.4 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
import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import legacy from '@vitejs/plugin-legacy'
import { VitePWA } from 'vite-plugin-pwa'
import tsconfigPaths from 'vite-tsconfig-paths'
const pathSrc = path.resolve(__dirname, './src')
const pathNodeModules = path.resolve(__dirname, './node_modules')
// https://vitejs.dev/config/
export default ({ mode }) => {
const env = loadEnv(mode, process.cwd())
const domain = env.VITE_APP_ENV !== 'prod' ? 'https://starter.jackple.com' : 'https://your_domain'
const base = env.VITE_APP_ENV !== 'prod' ? '/' : 'https://your_cdn_domain/'
const staticDomain = base === '/' ? domain + base : base
return defineConfig({
base,
plugins: [
tsconfigPaths(),
react(),
legacy({ targets: ['defaults', 'not IE 11'] }),
VitePWA({
base: '/',
workbox: {
cacheId: 'ts-react-vite',
clientsClaim: true,
skipWaiting: true,
offlineGoogleAnalytics: false,
inlineWorkboxRuntime: true,
runtimeCaching: [
{
// match html
urlPattern: new RegExp(domain),
handler: 'NetworkFirst'
},
{
// match static resource
urlPattern: new RegExp(`${staticDomain.replace(/\//g, '\\/')}\\/assets`),
handler: 'StaleWhileRevalidate'
}
]
}
})
// require('rollup-plugin-visualizer').default({ open: true, gzipSize: true, brotliSize: true })
],
css: {
preprocessorOptions: {
scss: {
charset: false,
additionalData: `
@import "${pathNodeModules.replace(/\\/g, '/')}/bourbon/core/_bourbon.scss";
@import "${pathSrc.replace(/\\/g, '/')}/styles/_base.scss";
`
},
less: {
modifyVars: {
'primary-color': '#1DA57A'
},
javascriptEnabled: true
}
}
}
})
}