Skip to content

Commit

Permalink
load envs in webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Nov 13, 2024
1 parent 28e8f5a commit f91452d
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
.DS_Store
.DS_Store
.env
37 changes: 37 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 @@ -15,6 +15,7 @@
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"css-loader": "^7.1.2",
"dotenv-webpack": "^8.1.0",
"file-loader": "^6.2.0",
"gh-pages": "^6.2.0",
"html-webpack-plugin": "^5.6.3",
Expand Down
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { createRoot } from "react-dom/client";
import Home from "./pages/Home";
import Other from "./pages/Other";
import Santa from "./pages/Santa";
import {
createHashRouter,
createRoutesFromElements,
Expand All @@ -12,7 +12,7 @@ import {
const router = createHashRouter(
createRoutesFromElements(
<>
<Route path="/other" element={<Other />} />
<Route path="/santa" element={<Santa />} />
<Route path="*" element={<Home />} />
</>
)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import "../App.css";
const Home = () => {
return (
<>
<Link to="/other">go to other</Link>
{/* <Link to="/other">go to other</Link>
<p>test css</p>
<img className="img-dvd" src={DVDImg} />
<img className="img-dvd" src={DVDImg} /> */}
</>
)
}
Expand Down
13 changes: 0 additions & 13 deletions src/pages/Other.tsx

This file was deleted.

9 changes: 9 additions & 0 deletions src/pages/Santa.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Santa = () => {
return (
<>
{process.env.SENDGRID_API_KEY}
</>
)
}

export default Santa;
21 changes: 9 additions & 12 deletions webpack.dev.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import HtmlWebpackPlugin from 'html-webpack-plugin';
const Dotenv = require('dotenv-webpack');

module.exports = {
entry: './src/index.tsx',
Expand All @@ -14,14 +15,7 @@ module.exports = {
},
{
test: /\.(jpe?g|gif|png|svg)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 10000
}
}
]
type: 'asset/resource'
},
{
test: /\.css$/i,
Expand All @@ -32,10 +26,13 @@ module.exports = {
devServer: {
historyApiFallback: true,
},
plugins: [new HtmlWebpackPlugin({
title: 'ewan sheldon',
favicon: "./public/me.jpg"
})],
plugins: [new Dotenv({
path: './.env', // Path to .env file (this is the default)
}),
new HtmlWebpackPlugin({
title: 'ewan sheldon',
favicon: "./public/me.jpg"
})],
resolve: {
extensions: ['.js', '.tsx'] // add your other extensions here
}
Expand Down
5 changes: 4 additions & 1 deletion webpack.prod.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ module.exports = {
},
plugins: [new HtmlWebpackPlugin({
title: 'ewan sheldon',
favicon: "./public/me.jpg"
favicon: "./public/me.jpg",
'process.env': {
'SENDGRID_API_KEY': JSON.stringify(process.env.SENDGRID_API_KEY)
}
})],
resolve: {
extensions: ['.js', '.tsx'] // add your other extensions here
Expand Down

0 comments on commit f91452d

Please sign in to comment.