Skip to content

Commit

Permalink
feat: environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbo-lab committed Oct 16, 2024
1 parent 4398721 commit 6e65255
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*node_modules/*
*node_modules/*
.env
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"bulma": "^1.0.2",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^7.1.2",
"dotenv": "^16.4.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.27.0",
Expand Down
17 changes: 14 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { DefinePlugin } = require("webpack");
const dotenv = require("dotenv");

// Load environment variables from .env file into process.env
const env = dotenv.config().parsed || {};

// Convert the env variables to a format DefinePlugin can understand
const envKeys = Object.keys(env).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});

module.exports = {
entry: "./src/index.js",
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist"),
clean: true, // Ensures dist/ is cleaned on each build
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
use: "babel-loader",
},
{
test: /\.css$/,
Expand All @@ -26,6 +36,7 @@ module.exports = {
new HtmlWebpackPlugin({
template: "./public/index.html",
}),
new DefinePlugin(envKeys), // Inject environment variables into the bundle
],
devServer: {
static: {
Expand Down

0 comments on commit 6e65255

Please sign in to comment.