Here\'s my webpack.config.js
\"use strict\";
module.exports = {
entry: [\'./main.js\'],
output: { path: __dirname, filename: \'bund
dotenv node module:dotenv:yarn add -D dotenv or npm i -D dotenv
.env file in your project root with the required variables:NODE_ENV=development
apiKey=w23io222929kdjfk
domain=example.domain.org
webpack.DefinePlugin:// webpack.config.js
const webpack = require('webpack')
const dotenv = require('dotenv')
module.exports = {
//...
plugins: [
// ...
new webpack.DefinePlugin({
'process.env': JSON.stringify(dotenv.config().parsed) // it will automatically pick up key values from .env file
})
// ...
]
//...
}
environment variables in your source code:// src/index.js
alert(process.env.NODE_ENV)
alert(process.env.apiKey)
dotenv: https://www.npmjs.com/package/dotenvwebpack.DefinePlugin: https://webpack.js.org/plugins/define-plugin/Good Luck...