I added react into django using webpack and when I created .env
file in app_name/
, I am trying to access environment variable like this process.env.base_url
but I am getting undefined.
file structure
Django_React
-- app_name
-- src
-- .env
-- urls.py
...
...
...
...
webpack.config.js
const path = require("path");
const webpack = require("webpack");
module.exports = {
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "./static/js"),
filename: "[name].js",
},
module: {
rules: [
{
test: /\.js|.jsx$/,
exclude: /node_modules/,
use: "babel-loader",
},
{
test: /\.css$/,
exclude: /node_modules/,
use: ["style-loader", "css-loader"],
},
],
},
optimization: {
minimize: true,
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("development"),
},
}),
],
};
How can I create and access environment variable if react app is created like this ?