Use dotenv with webpack.
npm install webpack-dotenv-pluginUse dotenv with webpack.
dotenv is a fantastic and useful way to
manage environment variables. I wanted to keep the good times going when
working with webpack for frontend projects.
```
npm i --save-dev webpack-dotenv-plugin
webpack-dotenv-plugin uses dotenv-safedotenv-safe
under the hood to read and check environment variables. The same options that
can be passed to can be passed to this plugin.
It then reads, parses and exports the listed env vars from .env intoprocess.env
stringified so it can be bundled for use with webpack.
Externally set environment variables will override vars set in .env.
`js
// webpack.config.js
const DotenvPlugin = require('webpack-dotenv-plugin');
module.exports = {
...
plugins: [
new DotenvPlugin({
sample: './.env.default',
path: './.env'
})
]
...
};
``