Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

Commit

Permalink
feat: add PRODUCTION constant to ESLint config
Browse files Browse the repository at this point in the history
As well as:
- Improving the docs as well
- Getting rid of usage in index.js
  • Loading branch information
mischah committed Mar 25, 2018
1 parent dd1f2a1 commit bb0c954
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Expand Up @@ -3,7 +3,10 @@
"parser": "babel-eslint",
"parserOptions": {
"allowImportExportEverywhere": true
},
},
"globals": {
"PRODUCTION": false
},
"overrides": [
{
"files": ["build/*.js"],
Expand Down
16 changes: 12 additions & 4 deletions README.md
Expand Up @@ -148,8 +148,12 @@ In the root directory is a file named `baumeister.json` which you can be used to
},
"webpack": {
"DefinePlugin": {
"development": {},
"production": {}
"development": {
"PRODUCTION": false
},
"production": {
"PRODUCTION": true
}
},
"ProvidePlugin": {
"$": "jquery",
Expand All @@ -167,8 +171,12 @@ The ramifications of changing the `useHandlebars` setting are explained in the s

### Define global constants at compile time

If you want to provide values for different types of builds (`NODE_ENV` is a popular example), you can define them inside the `dev` and `prod` properties of the `DefinePlugin` section.
The plugin does a direct text replacement, so the value given to it must include actual quotes inside of the string. You can use alternating quotes, like `"'production'"`, or use `JSON.stringify('production')`.
If you want to provide constants for different types of builds, you can define them inside the `development` and `production` properties of the `DefinePlugin` section.

The plugin does a direct text replacement, so the value given to it must include actual quotes inside of the string. You can use alternating quotes, like `"'My value'"`, or use `JSON.stringify('My value')`.

This is very useful to change behaviour between development and production build. For example adapting the URL prefix to an API. This is why we have predefined the constant `PRODUCTION`.

You may take a look at the official [Webpack DefinePlugin docs](https://webpack.js.org/plugins/define-plugin/).

### Automatically load modules instead of requiring / importing them
Expand Down
5 changes: 0 additions & 5 deletions src/app/index.js
Expand Up @@ -26,9 +26,4 @@ $(async () => {
ieViewportFix();

console.log('YaY, my first ES6-Module !!!!');
if (PRODUCTION) { // eslint-disable-line no-undef
console.log('Prod');
} else {
console.log('Dev');
}
});

0 comments on commit bb0c954

Please sign in to comment.