From e3237604770d98548fe7226772b7a4e92ddc36c1 Mon Sep 17 00:00:00 2001 From: ulises-jeremias Date: Tue, 28 Jun 2022 20:39:05 -0300 Subject: [PATCH] Fixed dotenv --- package-lock.json | 32 +++++++++++++++++++++++++------- package.json | 1 + webpack.config.js | 7 ++++++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1bda4bc6..18d465f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,7 @@ "copy-webpack-plugin": "^11.0.0", "css-loader": "^6.7.1", "danger": "^11.0.7", + "dotenv": "^16.0.1", "dotenv-webpack": "^7.1.0", "esbuild-jest": "^0.5.0", "esbuild-loader": "^2.19.0", @@ -5360,12 +5361,12 @@ "dev": true }, "node_modules/dotenv": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", - "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==", + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz", + "integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==", "dev": true, "engines": { - "node": ">=10" + "node": ">=12" } }, "node_modules/dotenv-defaults": { @@ -5377,6 +5378,15 @@ "dotenv": "^8.2.0" } }, + "node_modules/dotenv-defaults/node_modules/dotenv": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", + "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/dotenv-webpack": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/dotenv-webpack/-/dotenv-webpack-7.1.0.tgz", @@ -22579,9 +22589,9 @@ } }, "dotenv": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", - "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==", + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz", + "integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==", "dev": true }, "dotenv-defaults": { @@ -22591,6 +22601,14 @@ "dev": true, "requires": { "dotenv": "^8.2.0" + }, + "dependencies": { + "dotenv": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", + "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==", + "dev": true + } } }, "dotenv-webpack": { diff --git a/package.json b/package.json index 0906fe2d..9614bdd3 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "copy-webpack-plugin": "^11.0.0", "css-loader": "^6.7.1", "danger": "^11.0.7", + "dotenv": "^16.0.1", "dotenv-webpack": "^7.1.0", "esbuild-jest": "^0.5.0", "esbuild-loader": "^2.19.0", diff --git a/webpack.config.js b/webpack.config.js index a97f38bb..302e2ac3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,8 @@ +const path = require('path'); const { merge } = require('webpack-merge'); const commonConfig = require('./config/webpack.common.js'); +require('dotenv').config(); /** * getAddons is a function that returns valid addon modules @@ -15,7 +17,10 @@ const getAddons = (addons = '') => .map((name) => require(`./config/addons/webpack.${name}.js`)); module.exports = ({ env, addon }) => { - const envConfig = require(`./config/webpack.${env || 'production'}.js`); + const targetEnv = env || 'production'; + + require('dotenv').config({ path: path.resolve(process.cwd(), `.env.${targetEnv}`) }); + const envConfig = require(`./config/webpack.${targetEnv}.js`); return merge(commonConfig, envConfig, ...getAddons(addon)); };