diff --git a/packages/electron-webpack/package.json b/packages/electron-webpack/package.json index fbe5fe1..5cf830a 100644 --- a/packages/electron-webpack/package.json +++ b/packages/electron-webpack/package.json @@ -22,31 +22,32 @@ "dependencies": { "@types/webpack-env": "^1.13.6", "async-exit-hook": "^2.0.1", - "terser-webpack-plugin": "^1.1.0", "bluebird-lst": "^1.0.6", "chalk": "^2.4.1", "crocket": "^0.9.11", "css-hot-loader": "^1.4.2", "css-loader": "^1.0.1", "debug": "^4.1.0", + "dotenv": "^6.1.0", "electron-devtools-installer": "^2.2.4", "electron-webpack-js": "~2.3.0", - "mini-css-extract-plugin": "^0.4.4", "file-loader": "^2.0.0", "fs-extra-p": "^7.0.0", "html-loader": "^1.0.0-alpha.0", "html-webpack-plugin": "^3.2.0", "lazy-val": "^1.0.3", + "mini-css-extract-plugin": "^0.4.4", "node-loader": "^0.6.0", "read-config-file": "^3.1.3", "semver": "^5.6.0", "source-map-support": "^0.5.9", "style-loader": "^0.23.1", + "terser-webpack-plugin": "^1.1.0", "url-loader": "^1.1.2", + "webpack-cli": "^3.1.2", "webpack-dev-server": "^3.1.10", "webpack-merge": "^4.1.4", - "yargs": "^12.0.2", - "webpack-cli": "^3.1.2" + "yargs": "^12.0.2" }, "peerDependencies": { "webpack": "^4.8.3" diff --git a/packages/electron-webpack/src/main.ts b/packages/electron-webpack/src/main.ts index 47da84a..b053845 100644 --- a/packages/electron-webpack/src/main.ts +++ b/packages/electron-webpack/src/main.ts @@ -1,5 +1,5 @@ import BluebirdPromise from "bluebird-lst" -import { readJson } from "fs-extra-p" +import { readJson, pathExists } from "fs-extra-p" import { Lazy } from "lazy-val" import * as path from "path" import { validateConfig } from "read-config-file" @@ -332,6 +332,23 @@ export async function configure(type: ConfigurationType, env: ConfigurationEnv | return null } else { + const processEnv = configurator.isProduction ? "production" : "development" + const dotEnvPath = path.resolve(configurator.projectDir, ".env") + const dotenvFiles = [ + `${dotEnvPath}.${processEnv}.local`, + `${dotEnvPath}.${processEnv}`, + `${dotEnvPath}.local`, + dotEnvPath, + ] + + for (const file of dotenvFiles) { + const exists = await pathExists(file) + if (exists) { + require("dotenv").config({ + path: file + }) + } + } return await configurator.configure() } }