Skip to content

Commit

Permalink
feat: Support env variable using dot env (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenios authored and develar committed Nov 16, 2018
1 parent ba8dad0 commit d22c3bf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
9 changes: 5 additions & 4 deletions packages/electron-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 18 additions & 1 deletion packages/electron-webpack/src/main.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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()
}
}
Expand Down

0 comments on commit d22c3bf

Please sign in to comment.