Here is my webpack.config.js file for my react project.
const deps = require("./package.json").dependencies;
console.log({API_URL:process.env.API_URL})
module.exports = (env) => {
console.log({API_URL:process.env.API_URL})
return {
mode: env.file,
output: {
publicPath: "http://localhost:8000/",
},
resolve: {
extensions: [".tsx", ".ts", ".jsx", ".js", ".json"],
alias: {
'react': path.resolve(__dirname, 'node_modules/react'),
'react-dom': path.resolve(__dirname, 'node_modules/react-dom')
}
},
devServer: {
port: 8000,
historyApiFallback: true,
},
module: {
rules: [...],
},
plugins: [
new HtmlWebPackPlugin({
template: "./public/index.html",
}),
new Dotenv({
path: `./.env${env.file ? `.${env.file}` : ''}`
})
],
}
};
Why I am getting undefined here in the API_URL? How can I use env variable in webpack.config.js?