@@ -6,101 +6,107 @@ import vue from '@vitejs/plugin-vue'
6
6
import { visualizer } from 'rollup-plugin-visualizer'
7
7
import AutoImport from 'unplugin-auto-import/vite'
8
8
import Components from 'unplugin-vue-components/vite'
9
- import { defineConfig } from 'vite'
9
+ import { defineConfig , loadEnv } from 'vite'
10
10
import { nodePolyfills } from 'vite-plugin-node-polyfills'
11
11
import { VitePWA } from 'vite-plugin-pwa'
12
12
import { VitePluginRadar } from 'vite-plugin-radar'
13
13
import vueDevTools from 'vite-plugin-vue-devtools'
14
14
15
15
const base = process . env . SERVER_ENV === `NETLIFY` ? `/` : `/md/`
16
16
17
- export default defineConfig ( {
18
- base,
19
- define : { process } ,
20
- envPrefix : [ `VITE_` , `CF_` ] ,
21
- plugins : [
22
- vue ( ) ,
23
- tailwindcss ( ) ,
24
- vueDevTools ( ) ,
25
- VitePWA ( {
26
- registerType : `autoUpdate` ,
27
- includeAssets : [ `favicon.ico` ] ,
28
- manifest : {
29
- name : `@doocs-md` ,
30
- short_name : `@doocs-md` ,
31
- theme_color : `#ffffff` ,
32
- icons : [
33
- {
34
- src : `${ base } pwa-192x192.png` ,
35
- sizes : `192x192` ,
36
- type : `image/png` ,
37
- } ,
38
- {
39
- src : `${ base } pwa-512x512.png` ,
40
- sizes : `512x512` ,
41
- type : `image/png` ,
42
- } ,
43
- {
44
- src : `${ base } pwa-512x512.png` ,
45
- sizes : `512x512` ,
46
- type : `image/png` ,
47
- purpose : `any maskable` ,
48
- } ,
49
- ] ,
50
- } ,
51
- workbox : {
52
- maximumFileSizeToCacheInBytes : 6 * 1024 * 1024 ,
53
- } ,
54
- devOptions : {
55
- enabled : true ,
56
- } ,
57
- } ) ,
58
- nodePolyfills ( {
59
- include : [ `path` , `util` , `timers` , `stream` , `fs` ] ,
60
- overrides : {
17
+ export default defineConfig ( ( { mode } ) => {
18
+ const env = loadEnv ( mode , process . cwd ( ) )
19
+
20
+ return {
21
+ base,
22
+ define : { process } ,
23
+ envPrefix : [ `VITE_` , `CF_` ] ,
24
+ plugins : [
25
+ vue ( ) ,
26
+ tailwindcss ( ) ,
27
+ vueDevTools ( {
28
+ launchEditor : env . VITE_LAUNCH_EDITOR ?? `code` ,
29
+ } ) ,
30
+ VitePWA ( {
31
+ registerType : `autoUpdate` ,
32
+ includeAssets : [ `favicon.ico` ] ,
33
+ manifest : {
34
+ name : `@doocs-md` ,
35
+ short_name : `@doocs-md` ,
36
+ theme_color : `#ffffff` ,
37
+ icons : [
38
+ {
39
+ src : `${ base } pwa-192x192.png` ,
40
+ sizes : `192x192` ,
41
+ type : `image/png` ,
42
+ } ,
43
+ {
44
+ src : `${ base } pwa-512x512.png` ,
45
+ sizes : `512x512` ,
46
+ type : `image/png` ,
47
+ } ,
48
+ {
49
+ src : `${ base } pwa-512x512.png` ,
50
+ sizes : `512x512` ,
51
+ type : `image/png` ,
52
+ purpose : `any maskable` ,
53
+ } ,
54
+ ] ,
55
+ } ,
56
+ workbox : {
57
+ maximumFileSizeToCacheInBytes : 6 * 1024 * 1024 ,
58
+ } ,
59
+ devOptions : {
60
+ enabled : true ,
61
+ } ,
62
+ } ) ,
63
+ nodePolyfills ( {
64
+ include : [ `path` , `util` , `timers` , `stream` , `fs` ] ,
65
+ overrides : {
61
66
// Since `fs` is not supported in browsers, we can use the `memfs` package to polyfill it.
62
67
// fs: 'memfs',
63
- } ,
64
- } ) ,
65
- VitePluginRadar ( {
66
- analytics : { id : `G-7NZL3PZ0NK` } ,
67
- } ) ,
68
- process . env . ANALYZE === `true`
69
- && visualizer ( { emitFile : true , filename : `stats.html` } ) ,
70
- AutoImport ( {
71
- imports : [ `vue` , `pinia` , `@vueuse/core` ] ,
72
- dirs : [ `./src/stores` , `./src/utils/toast` , `./src/composables` ] ,
73
- } ) ,
74
- Components ( {
75
- resolvers : [ ] ,
76
- } ) ,
77
- ] ,
78
- resolve : {
79
- alias : { '@' : path . resolve ( __dirname , `./src` ) } ,
80
- } ,
81
- css : { devSourcemap : true } ,
82
- build : {
83
- rollupOptions : {
84
- output : {
85
- chunkFileNames : `static/js/md-[name]-[hash].js` ,
86
- entryFileNames : `static/js/md-[name]-[hash].js` ,
87
- assetFileNames : `static/[ext]/md-[name]-[hash].[ext]` ,
88
- manualChunks ( id ) {
89
- if ( id . includes ( `node_modules` ) ) {
90
- if ( id . includes ( `katex` ) )
91
- return `katex`
92
- if ( id . includes ( `mermaid` ) )
93
- return `mermaid`
94
- if ( id . includes ( `highlight.js` ) )
95
- return `hljs`
96
- const pkg = id
97
- . split ( `node_modules/` ) [ 1 ]
98
- . split ( `/` ) [ 0 ]
99
- . replace ( `@` , `npm_` )
100
- return `vendor_${ pkg } `
101
- }
68
+ } ,
69
+ } ) ,
70
+ VitePluginRadar ( {
71
+ analytics : { id : `G-7NZL3PZ0NK` } ,
72
+ } ) ,
73
+ process . env . ANALYZE === `true`
74
+ && visualizer ( { emitFile : true , filename : `stats.html` } ) ,
75
+ AutoImport ( {
76
+ imports : [ `vue` , `pinia` , `@vueuse/core` ] ,
77
+ dirs : [ `./src/stores` , `./src/utils/toast` , `./src/composables` ] ,
78
+ } ) ,
79
+ Components ( {
80
+ resolvers : [ ] ,
81
+ } ) ,
82
+ ] ,
83
+ resolve : {
84
+ alias : { '@' : path . resolve ( __dirname , `./src` ) } ,
85
+ } ,
86
+ css : { devSourcemap : true } ,
87
+ build : {
88
+ rollupOptions : {
89
+ output : {
90
+ chunkFileNames : `static/js/md-[name]-[hash].js` ,
91
+ entryFileNames : `static/js/md-[name]-[hash].js` ,
92
+ assetFileNames : `static/[ext]/md-[name]-[hash].[ext]` ,
93
+ manualChunks ( id ) {
94
+ if ( id . includes ( `node_modules` ) ) {
95
+ if ( id . includes ( `katex` ) )
96
+ return `katex`
97
+ if ( id . includes ( `mermaid` ) )
98
+ return `mermaid`
99
+ if ( id . includes ( `highlight.js` ) )
100
+ return `hljs`
101
+ const pkg = id
102
+ . split ( `node_modules/` ) [ 1 ]
103
+ . split ( `/` ) [ 0 ]
104
+ . replace ( `@` , `npm_` )
105
+ return `vendor_${ pkg } `
106
+ }
107
+ } ,
102
108
} ,
103
109
} ,
104
110
} ,
105
- } ,
111
+ }
106
112
} )
0 commit comments