File tree 1 file changed +11
-5
lines changed
packages/@vuepress/bundler-vite/src/plugins
1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ const vueTemplateBreaker = '<wbr>'
15
15
* constant strings in page data, and insert `<wbr>` tag into constant strings
16
16
* in template of page component.
17
17
*
18
+ * Notice that `process.env.NODE_ENV` will be statically replaced even
19
+ * in dev mode, while the vite docs does not mention it yet.
20
+ *
18
21
* @see https://vitejs.dev/guide/env-and-mode.html#production-replacement
19
22
*/
20
23
export const constantsReplacementPlugin = ( app : App ) : Plugin => {
@@ -32,13 +35,16 @@ export const constantsReplacementPlugin = (app: App): Plugin => {
32
35
33
36
enforce : 'pre' ,
34
37
35
- apply : 'build' ,
36
-
37
38
configResolved ( resolvedConfig ) {
38
- const constants = [ 'import.meta' , 'process.env' ]
39
+ // `process.env` need to be handled in both dev and build
40
+ // @see https://github.com/vitejs/vite/blob/cad27ee8c00bbd5aeeb2be9bfb3eb164c1b77885/packages/vite/src/node/plugins/clientInjections.ts#L57-L64
41
+ const constants = [ 'process.env' ]
39
42
40
- if ( resolvedConfig . define ) {
41
- constants . push ( ...Object . keys ( resolvedConfig . define ) )
43
+ if ( app . env . isBuild ) {
44
+ constants . push ( 'import.meta' )
45
+ if ( resolvedConfig . define ) {
46
+ constants . push ( ...Object . keys ( resolvedConfig . define ) )
47
+ }
42
48
}
43
49
44
50
constantsRegexp = new RegExp (
You can’t perform that action at this time.
0 commit comments