Skip to content

Commit bff1648

Browse files
committed
Added global configuration object and aliases
1 parent a99519d commit bff1648

File tree

17 files changed

+160
-5
lines changed

17 files changed

+160
-5
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"react/jsx-no-bind": 0,
1313
"strict": 0,
1414
"no-unused-expressions": 0,
15-
"no-underscore-dangle": [ "error", { "allowAfterThis": true }]
15+
"no-underscore-dangle": [ "error", { "allowAfterThis": true }],
16+
"import/no-unresolved": [ "error", "ignore": [ 'config' ] ]
1617
}
1718
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ The following features are currently included out of the box:
1919

2020
## Common Questions:
2121

22+
- I want to use react-router, but I dont know how to set it up:
23+
FOLLOWS
24+
2225
- I want to use less/sass/whatever, but get an error when requiring the file:
2326
We currently do not ship the needed modules. This is done on purpose, as we dont want you to install too much dependencies. If you do not use a css precompiler, chance is you wont even notice it. If you need one, just install the required webpack loader (e.g. for less via ```npm install --save-dev less-loader```).
2427

conf/webpack/Base.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,29 @@ class WebpackBaseConfig {
3030
return this._config;
3131
}
3232

33+
/**
34+
* Get the environment name
35+
* @return {String} The current environment
36+
*/
37+
get env() {
38+
return 'dev';
39+
}
40+
41+
/**
42+
* Get the absolute path to src directory
43+
* @return {String}
44+
*/
45+
get srcPathAbsolute() {
46+
return path.resolve('./src');
47+
}
48+
3349
/**
3450
* Get the default settings
3551
* @return {Object}
3652
*/
3753
get defaultSettings() {
3854
return {
39-
context: path.resolve('./src'),
55+
context: this.srcPathAbsolute,
4056
debug: false,
4157
devtool: 'eval',
4258
devServer: {
@@ -46,6 +62,13 @@ class WebpackBaseConfig {
4662
},
4763
entry: './index.js',
4864
module: {
65+
preLoaders: [
66+
{
67+
test: /\.(js|jsx)$/,
68+
include: this.srcPathAbsolute,
69+
loader: 'eslint'
70+
}
71+
],
4972
loaders: [
5073
{
5174
test: /\.css$/,
@@ -74,7 +97,7 @@ class WebpackBaseConfig {
7497
{
7598
test: /\.(js|jsx)$/,
7699
include: [
77-
path.resolve('src')
100+
this.srcPathAbsolute
78101
],
79102
loaders: ['babel']
80103
}
@@ -87,9 +110,17 @@ class WebpackBaseConfig {
87110
},
88111
plugins: [],
89112
resolve: {
113+
alias: {
114+
actions: `${this.srcPathAbsolute}/actions/`,
115+
components: `${this.srcPathAbsolute}/components/`,
116+
config: `${this.srcPathAbsolute}/config/${this.env}.js`,
117+
images: `${this.srcPathAbsolute}/images/`,
118+
sources: `${this.srcPathAbsolute}/sources/`,
119+
stores: `${this.srcPathAbsolute}/stores/`
120+
},
90121
extensions: ['', '.js', '.jsx'],
91122
modules: [
92-
path.resolve('./src'),
123+
this.srcPathAbsolute,
93124
'node_modules'
94125
]
95126
}

conf/webpack/Dist.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@ class WebpackDistConfig extends WebpackBaseConfig {
1414
this.config = {
1515
devtool: 'source-map',
1616
plugins: [
17+
new webpack.DefinePlugin({
18+
'process.env.NODE_ENV': '"production"'
19+
}),
1720
new webpack.optimize.DedupePlugin(),
1821
new webpack.optimize.AggressiveMergingPlugin()
1922
]
2023
};
2124
}
25+
26+
/**
27+
* Get the environment name
28+
* @return {String} The current environment
29+
*/
30+
get env() {
31+
return 'dist';
32+
}
2233
}
2334

2435
module.exports = WebpackDistConfig;

conf/webpack/Test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
'use strict';
55
const WebpackBaseConfig = require('./Base');
6+
const webpack = require('webpack');
67

78
class WebpackTestConfig extends WebpackBaseConfig {
89

@@ -27,9 +28,22 @@ class WebpackTestConfig extends WebpackBaseConfig {
2728
presets: ['react', 'es2015', 'stage-0'],
2829
}
2930
}
31+
],
32+
plugins: [
33+
new webpack.DefinePlugin({
34+
'process.env.NODE_ENV': '"test"'
35+
})
3036
]
3137
};
3238
}
39+
40+
/**
41+
* Get the environment name
42+
* @return {String} The current environment
43+
*/
44+
get env() {
45+
return 'test';
46+
}
3347
}
3448

3549
module.exports = WebpackTestConfig;

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
"scripts": {
77
"start": "npm run serve:dev",
88
"test": "mocha",
9+
"posttest": "npm run lint",
910
"test:watch": "mocha -w",
1011
"cover": "babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha",
1112
"serve:dev": "webpack-dev-server --open --env dev",
12-
"dist": "webpack --progress --bail --env dist -p"
13+
"serve:dist": "webpack-dev-server --open --env dist",
14+
"dist": "webpack --progress --bail --env dist -p",
15+
"lint": "eslint ./src"
1316
},
1417
"repository": {
1518
"type": "git",
@@ -42,6 +45,7 @@
4245
"enzyme": "^2.2.0",
4346
"eslint": "^2.8.0",
4447
"eslint-config-airbnb": "^9.0.0",
48+
"eslint-loader": "^1.3.0",
4549
"eslint-plugin-import": "^1.4.0",
4650
"eslint-plugin-jsx-a11y": "^1.0.0",
4751
"eslint-plugin-react": "^5.0.0",

src/actions/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# About this folder
2+
This folder will hold all of your **flux** actions if you are using flux.
3+
You can include actions into your components or stores like this:
4+
5+
```javascript
6+
let react = require('react/addons');
7+
let MyAction = require('actions/MyAction');
8+
class MyComponent extends React.Component {
9+
constructor(props) {
10+
super(props);
11+
MyAction.exampleMethod();
12+
}
13+
}
14+
```

src/config/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# About this folder
2+
This folder holds configuration files for different environments.
3+
You can use it to provide your app with different settings based on the
4+
current environment, e.g. to configure different API base urls depending on
5+
whether your setup runs in dev mode or is built for distribution.
6+
You can include the configuration into your code like this:
7+
8+
```javascript
9+
let react = require('react/addons');
10+
let config = require('config');
11+
class MyComponent extends React.Component {
12+
constructor(props) {
13+
super(props);
14+
let currentAppEnv = config.appEnv;
15+
}
16+
}
17+
```

src/config/base.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
// Settings configured here will be merged into the final config object.
4+
export default {
5+
};

src/config/dev.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
import baseConfig from './base';
4+
5+
const config = {
6+
appEnv: 'dev'
7+
};
8+
9+
export default Object.freeze(Object.assign({}, baseConfig, config));

0 commit comments

Comments
 (0)