Skip to content

Commit

Permalink
refactor(Environment variables): Using node-config through Webpack
Browse files Browse the repository at this point in the history
Using node-config through Webpack as a Plugin
  • Loading branch information
Anas Tiour committed Dec 25, 2018
1 parent c508cf3 commit 7ef9f45
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ In order to keep the `graphql-shield` and `nuxt-frontend` branches in sync with

## Todos and roadmap

- NodeJS best practices checklist
[NodeJS best practices checklist](https://github.com/i0natan/nodebestpractices):
- 1.5 Use environment aware, secure and hierarchical config

Using the [node-config] package with Webpack. See [](https://github.com/lorenwest/node-config/wiki/Webpack-Usage)

- Clean datasources
- Documentation and references
11 changes: 3 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@graphql-modules/core": "0.2.17",
"apollo-server": "2.1.0",
"config": "^3.0.1",
"dotenv": "6.1.0",
"graphql": "0.13.2",
"js-yaml": "^3.12.0",
"merge-graphql-schemas": "1.5.7",
Expand Down
10 changes: 1 addition & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@ import config from "config"

if (process.env.NODE_ENV === "production") {
// require("dotenv").load()
require("dotenv").config()
console.log("PROD")
console.log(process.env.NODE_ENV)
}

if (process.env.NODE_ENV === "development") {
// require("dotenv").load()
require("dotenv").config({
path: ".env.dev",
})
console.log("DEV")
console.log(process.env.NODE_ENV)
const customerConfig = config.get("Customer.testVar")
console.log(customerConfig)
console.log(CONFIG)
}

const port = process.env.PORT || 4000
Expand Down
4 changes: 3 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ module.exports = {
plugins: [
// HMR should never be used in production
new webpack.HotModuleReplacementPlugin(),
// https://github.com/lorenwest/node-config/wiki/Webpack-Usage
new webpack.DefinePlugin({ CONFIG: JSON.stringify(require("config")) }),
],

optimization: {
// namedModules: true, // Not set, since used in dev mode and not in pro
noEmitOnErrors: true,
},
}
}

0 comments on commit 7ef9f45

Please sign in to comment.