File tree 2 files changed +44
-2
lines changed
2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { resolve } from "path" ;
2
- import { defineConfig , UserConfig } from "vite" ;
2
+ import { defineConfig , PluginOption , UserConfig } from "vite" ;
3
3
import dts from "vite-plugin-dts" ;
4
4
5
+ const handleEnvVariablesPlugin = ( ) : PluginOption => {
6
+ return {
7
+ name : "handle-env-variables-plugin" ,
8
+ generateBundle ( options , bundle ) {
9
+ for ( const fileName in bundle ) {
10
+ const file = bundle [ fileName ] ;
11
+
12
+ if ( file . type === "chunk" && file . fileName . endsWith ( ".js" ) ) {
13
+ const transformedContent = file . code . replace (
14
+ / i m p o r t \. m e t a \. e n v \. V I T E _ ( [ A - Z 0 - 9 _ ] + ) / g,
15
+ "(typeof import.meta.env !== 'undefined' ? import.meta.env.VITE_$1 : undefined)" ,
16
+ ) ;
17
+
18
+ file . code = transformedContent ;
19
+ }
20
+ }
21
+ } ,
22
+ } ;
23
+ } ;
24
+
5
25
const config : UserConfig = ( ( ) => {
6
26
const common : Partial < UserConfig [ "build" ] > = {
7
27
rollupOptions : {
@@ -40,6 +60,7 @@ const config: UserConfig = (() => {
40
60
rollupTypes : true ,
41
61
include : [ "src/**/*.ts" ] ,
42
62
} ) ,
63
+ handleEnvVariablesPlugin ( ) ,
43
64
] ,
44
65
define : {
45
66
"import.meta.env.VITE_REVERB_APP_KEY" :
Original file line number Diff line number Diff line change 1
1
import { resolve } from "path" ;
2
- import { defineConfig , UserConfig } from "vite" ;
2
+ import { defineConfig , PluginOption , UserConfig } from "vite" ;
3
3
import dts from "vite-plugin-dts" ;
4
4
5
+ const handleEnvVariablesPlugin = ( ) : PluginOption => {
6
+ return {
7
+ name : "handle-env-variables-plugin" ,
8
+ generateBundle ( options , bundle ) {
9
+ for ( const fileName in bundle ) {
10
+ const file = bundle [ fileName ] ;
11
+
12
+ if ( file . type === "chunk" && file . fileName . endsWith ( ".js" ) ) {
13
+ const transformedContent = file . code . replace (
14
+ / i m p o r t \. m e t a \. e n v \. V I T E _ ( [ A - Z 0 - 9 _ ] + ) / g,
15
+ "(typeof import.meta.env !== 'undefined' ? import.meta.env.VITE_$1 : undefined)" ,
16
+ ) ;
17
+
18
+ file . code = transformedContent ;
19
+ }
20
+ }
21
+ } ,
22
+ } ;
23
+ } ;
24
+
5
25
const config : UserConfig = ( ( ) => {
6
26
const common : Partial < UserConfig [ "build" ] > = {
7
27
rollupOptions : {
@@ -40,6 +60,7 @@ const config: UserConfig = (() => {
40
60
rollupTypes : true ,
41
61
include : [ "src/**/*.ts" ] ,
42
62
} ) ,
63
+ handleEnvVariablesPlugin ( ) ,
43
64
] ,
44
65
define : {
45
66
"import.meta.env.VITE_REVERB_APP_KEY" :
You can’t perform that action at this time.
0 commit comments