diff --git a/webpack.common.js b/webpack.common.js index 3d029a2b..b4958f4b 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -1,6 +1,14 @@ const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const webpack = require('webpack'); +const dotenv = require('dotenv'); + +const env = dotenv.config().parsed || {}; + +const envKeys = Object.keys(env).reduce((prev, next) => { + prev[`process.env.${next}`] = JSON.stringify(env[next]); + return prev; +}, {}); const config = { entry: ['./src/index.jsx'], @@ -64,9 +72,7 @@ const config = { template: './public/index.html', favicon: './public/favicon.ico', }), - new webpack.DefinePlugin({ - 'process.env': JSON.stringify(process.env), - }), + new webpack.DefinePlugin(envKeys), ], };