Skip to content

Commit 786939b

Browse files
Merge pull request #1036 from ProvableHQ/fix/amplitude-webpack-config
fix amplitude webpack config
2 parents a911309 + 1ee5e92 commit 786939b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@vitejs/plugin-react-swc": "^3.7.2",
4343
"copy-webpack-plugin": "^12.0.2",
4444
"css-loader": "^7.1.2",
45+
"dotenv": "^16.3.1",
4546
"eslint": "^9.19.0",
4647
"eslint-plugin-react": "^7.37.4",
4748
"eslint-plugin-react-hooks": "^5.1.0",

website/src/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { init } from '@amplitude/analytics-browser';
88
import { autocapturePlugin } from '@amplitude/plugin-autocapture-browser';
99

1010
// 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;
1212

1313
if (AMPLITUDE_API_KEY) {
1414
init(AMPLITUDE_API_KEY, {

website/webpack.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import CopyPlugin from "copy-webpack-plugin";
22
import TerserPlugin from "terser-webpack-plugin";
33
import HtmlWebpackPlugin from "html-webpack-plugin";
4-
4+
import webpack from "webpack";
5+
import dotenv from "dotenv";
56
import path from "path";
67

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+
715
const appConfig = {
816
mode: "production",
917
entry: {
@@ -52,6 +60,7 @@ const appConfig = {
5260
new HtmlWebpackPlugin({
5361
template: "./index.html",
5462
}),
63+
new webpack.DefinePlugin(envKeys),
5564
],
5665
optimization: {
5766
minimize: true,

0 commit comments

Comments
 (0)