File tree 3 files changed +12
-2
lines changed
3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 42
42
"@vitejs/plugin-react-swc" : " ^3.7.2" ,
43
43
"copy-webpack-plugin" : " ^12.0.2" ,
44
44
"css-loader" : " ^7.1.2" ,
45
+ "dotenv" : " ^16.3.1" ,
45
46
"eslint" : " ^9.19.0" ,
46
47
"eslint-plugin-react" : " ^7.37.4" ,
47
48
"eslint-plugin-react-hooks" : " ^5.1.0" ,
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { init } from '@amplitude/analytics-browser';
8
8
import { autocapturePlugin } from '@amplitude/plugin-autocapture-browser' ;
9
9
10
10
// Initialize Amplitude with your API key
11
- const AMPLITUDE_API_KEY = import . meta . env . VITE_AMPLITUDE_API_KEY ;
11
+ const AMPLITUDE_API_KEY = process . env . VITE_AMPLITUDE_API_KEY ;
12
12
13
13
if ( AMPLITUDE_API_KEY ) {
14
14
init ( AMPLITUDE_API_KEY , {
Original file line number Diff line number Diff line change 1
1
import CopyPlugin from "copy-webpack-plugin" ;
2
2
import TerserPlugin from "terser-webpack-plugin" ;
3
3
import HtmlWebpackPlugin from "html-webpack-plugin" ;
4
-
4
+ import webpack from "webpack" ;
5
+ import dotenv from "dotenv" ;
5
6
import path from "path" ;
6
7
8
+ const env = dotenv . config ( ) . parsed || { } ;
9
+ const envKeys = Object . keys ( env ) . reduce ( ( acc , key ) => {
10
+ acc [ `process.env.${ key } ` ] = JSON . stringify ( env [ key ] ) ;
11
+ return acc ;
12
+ } , { } ) ;
13
+
14
+
7
15
const appConfig = {
8
16
mode : "production" ,
9
17
entry : {
@@ -52,6 +60,7 @@ const appConfig = {
52
60
new HtmlWebpackPlugin ( {
53
61
template : "./index.html" ,
54
62
} ) ,
63
+ new webpack . DefinePlugin ( envKeys ) ,
55
64
] ,
56
65
optimization : {
57
66
minimize : true ,
You can’t perform that action at this time.
0 commit comments