Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/with-universal-configuration/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"next/babel"
],
"plugins": [
["transform-define", "./env-config.js"]
["transform-define", "./config/index.js"]
]
}
12 changes: 12 additions & 0 deletions examples/with-universal-configuration/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const commandLineArgs = require('command-line-args');

const optionDefinitions = [
{ name: 'env', alias: 'e', type: String }
];

const args = commandLineArgs(optionDefinitions);
const config = args.env === "production" ? require( "./prodConfig" ) : require( "./localConfig" );

module.exports = {
'BACKEND_URL': config.backendUrl
}
3 changes: 3 additions & 0 deletions examples/with-universal-configuration/config/localConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
backendUrl: "http://localhost:3000"
}
3 changes: 3 additions & 0 deletions examples/with-universal-configuration/config/prodConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
backendUrl: "http://www.production.com"
}
5 changes: 0 additions & 5 deletions examples/with-universal-configuration/env-config.js

This file was deleted.

6 changes: 5 additions & 1 deletion examples/with-universal-configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"clean": "rimraf .\\node_modules\\.cache",
"build-dev": "npm run clean && next build --env=development",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not simply

"build-dev": "npm run clean && next build",
"build-prod": "npm run clean && NODE_ENV=production next build"

?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we need to pass additional parameters like instance (we need to pass 2 params)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then can just add another env var.

IMHO that's unrelated to what the example is trying to convey. There's no need for command-line-args to get universal config working.

"build-prod": "npm run clean && next build --env=production",
"start": "next start"
},
"dependencies": {
Expand All @@ -12,6 +14,8 @@
"react-dom": "^15.4.2"
},
"devDependencies": {
"command-line-args": "^4.0.2",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand why this package was needed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this package makes params from command line easy to collect

"rimraf": "^2.6.1",
"babel-plugin-transform-define": "^1.2.0"
},
"author": "",
Expand Down