Skip to content
This repository was archived by the owner on Sep 11, 2018. It is now read-only.

Commit cde2bb0

Browse files
author
David Zukowski
committed
refactor(all): ports progress from a recent project that better supports isomorphic rendering
1 parent b71d6d7 commit cde2bb0

37 files changed

+306
-223
lines changed

.eslintrc

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
"destructuring": 1
1111
},
1212
"globals": {
13-
"__DEV__" : false,
14-
"__PROD__" : false
13+
"__DEV__" : false,
14+
"__PROD__" : false,
15+
"__CLIENT__" : false,
16+
"__SERVER__" : false
1517
},
1618
"plugins": [],
1719
"rules": {
@@ -67,7 +69,7 @@
6769
"no-labels": 2,
6870
"no-lone-blocks": 2,
6971
"no-loop-func": 2,
70-
"no-multi-spaces": [1, {
72+
"no-multi-spaces": [0, {
7173
"exceptions": {}
7274
}],
7375
"no-multi-str": 2,
@@ -104,7 +106,7 @@
104106
"no-undef": 2,
105107
"no-undef-init": 0,
106108
"no-undefined": 2,
107-
"no-unused-vars": 1,
109+
"no-unused-vars": 0,
108110
"no-use-before-define": 2,
109111

110112
"array-bracket-spacing": 0,
@@ -149,7 +151,6 @@
149151
"no-spaced-func": 2,
150152
"no-ternary": 0,
151153
"no-trailing-spaces": 1,
152-
"no-multiple-empty-lines": 1,
153154
"no-underscore-dangle": 0,
154155
"no-unneeded-ternary": 2,
155156
"object-curly-spacing": [1, "always"],
@@ -191,7 +192,7 @@
191192
"no-this-before-super": 2,
192193
"no-var": 0,
193194
"object-shorthand": 0,
194-
"perfer-const": 1,
195+
"prefer-const": 1,
195196

196197
"max-depth": [2, 3],
197198
"max-len": [2, 80, 2],

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
language: node_js
22
node_js:
3+
- "0.12"
34
- "iojs"
45

56
install:
67
- npm install
78

89
script:
9-
- npm run deploy
10+
- NODE_ENV=production npm run deploy

LICENSE

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
copies of the Software, and to permit persons to whom the Software is
1010
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in
13-
all copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+2-50
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,2 @@
1-
< Wirk />
2-
=========
3-
[![Build Status](https://travis-ci.org/davezuko/wirk-starter.svg?branch=master)](https://travis-ci.org/davezuko/wirk-starter/)
4-
5-
A basic starter kit that gives you just enough boilerplate to start building Isomorphic React applications with Koa.js, while staying out of your way.
6-
7-
Requirements
8-
------------
9-
IO.js is recommended, with --harmony flag enabled if you're not using our predefined npm scripts.
10-
11-
Features
12-
--------
13-
* Webpack
14-
* Separate client and server bundles
15-
* Default loaders for `.js`, `.jsx` and `.css` (relax, it's with PostCSS)
16-
* Hot Module Replacement with the help of React Hot Loader
17-
* Development scripts to enable live-reloading with hot module replacement
18-
* Koa.js as a back-end server
19-
* Jade for html pre-processing
20-
* Easy environment-specific configuration, which already includes:
21-
* Client bundle splitting in production mode
22-
* CSS Extraction in production mode
23-
24-
Installation
25-
-------------
26-
27-
Install project dependencies with:
28-
```
29-
npm run setup
30-
```
31-
32-
Once this is done, you can either run the development server with
33-
34-
```
35-
npm run dev
36-
37-
// or
38-
39-
npm run dev:quiet // disables verbose debugging
40-
```
41-
42-
or compile the application to disk for use with the server
43-
44-
```
45-
npm run build && npm run server:start
46-
```
47-
48-
Configuration
49-
-------------
50-
Basic project configuration can be found in `~/confg/index.js` and includes options for source and dist directories, default ports, and a list of vendor dependencies (used for bundle splitting during client compilation). In the future this file will hopefully become more powerful so that the application can be more heavily tweaked without having to dig through the source.
1+
Isomorphic React Webpack Starter Kit
2+
====================================

app/components/app/index.jsx

-14
This file was deleted.

app/entry-points/client.js

-6
This file was deleted.

app/entry-points/server.js

-3
This file was deleted.

app/styles/core.css

-1
This file was deleted.

build/karma/configs/_development.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default (config) => {
2+
config.singleRun = false;
3+
4+
return config;
5+
};

build/karma/configs/_production.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { DIST_DIRNAME } from '../../../config';
2+
3+
export default (config) => {
4+
config.singleRun = true;
5+
config.reporters = ['spec', 'coverage'];
6+
config.coverageReporter = {
7+
type : 'html',
8+
dir : `${DIST_DIRNAME}/coverage/`
9+
};
10+
11+
return config;
12+
};

build/karma/make-config.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { NODE_ENV, SRC_DIRNAME } from '../../config';
2+
import makeWebpackConfig from '../webpack/make-config';
3+
4+
const KARMA_ENTRY = 'karma.entry.js';
5+
const WEBPACK_CONFIG = makeWebpackConfig(
6+
require('../webpack/client')('development')
7+
);
8+
9+
function makeDefaultConfig () {
10+
return {
11+
files : [
12+
'./node_modules/phantomjs-polyfill/bind-polyfill.js',
13+
`./${KARMA_ENTRY}`
14+
],
15+
frameworks : ['chai', 'mocha'],
16+
preprocessors : {
17+
[KARMA_ENTRY] : ['webpack'],
18+
[`${SRC_DIRNAME}/**/*.js`] : ['webpack']
19+
},
20+
reporters : ['spec'],
21+
browsers : ['PhantomJS'],
22+
webpack : {
23+
devtool : 'inline-source-map',
24+
resolve : WEBPACK_CONFIG.resolve,
25+
module : {
26+
loaders : WEBPACK_CONFIG.module.loaders
27+
}
28+
},
29+
webpackMiddleware : {
30+
noInfo : true
31+
},
32+
plugins: [
33+
require('karma-webpack'),
34+
require('karma-mocha'),
35+
require('karma-chai'),
36+
require('karma-coverage'),
37+
require('karma-phantomjs-launcher'),
38+
require('karma-spec-reporter')
39+
]
40+
};
41+
}
42+
43+
export default function (karmaConfig) {
44+
return karmaConfig.set(
45+
require(`./configs/_${NODE_ENV}`)(makeDefaultConfig())
46+
);
47+
};

build/webpack/client/_production.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import webpack from 'webpack';
22
import ExtractTextPlugin from 'extract-text-webpack-plugin';
3-
import { VENDOR_DEPENDENCIES } from '../../../config';
43

54
export default function (config) {
6-
config.entry.vendor = VENDOR_DEPENDENCIES;
75
config.plugins.push(
8-
new webpack.optimize.CommonsChunkPlugin('vendor', '[name].[hash].js'),
96
new ExtractTextPlugin('[name].[contenthash].css')
107
);
118

129
config.module.loaders = config.module.loaders.map(loader => {
1310

1411
// Extract CSS to a file
15-
if (/\.css/.test(loader.test)) {
12+
if (/css/.test(loader.test)) {
1613
loader.loader = ExtractTextPlugin.extract(
1714
loader.loaders[0], loader.loaders.slice(1).join('!')
1815
);

build/webpack/client/index.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import webpack from 'webpack';
2-
import autoprefixer from 'autoprefixer-core';
3-
import csswring from 'csswring';
42
import HtmlWebpackPlugin from 'html-webpack-plugin';
53
import makeConfig from '../make-config';
6-
import { inSrc, inDist } from '../../../lib/path';
7-
import { NODE_ENV } from '../../../lib/environment';
4+
import { inSrc, inDist, NODE_ENV, VENDOR_DEPENDENCIES } from '../../../config';
85

96
const config = makeConfig({
107
name : 'Client',
118
target : 'web',
129
entry : {
1310
app : [
1411
inSrc('entry-points/client')
15-
]
12+
],
13+
vendor : VENDOR_DEPENDENCIES
1614
},
1715
output : {
1816
filename : '[name].[hash].js',
@@ -31,18 +29,25 @@ config.plugins.push(
3129
new HtmlWebpackPlugin({
3230
template : inSrc('index.html'),
3331
hash : true
34-
})
32+
}),
33+
new webpack.optimize.CommonsChunkPlugin('vendor', '[name].[hash].js')
3534
);
3635

3736
// ------------------------------------
3837
// Client-Specific Loaders
3938
// ------------------------------------
4039
config.module.loaders.push(
4140
{
42-
test : /\.css$/,
43-
loaders : ['style', 'css', 'postcss']
41+
test : /\.scss$/,
42+
loaders : [
43+
'style-loader',
44+
'css-loader',
45+
'autoprefixer?browsers=last 2 version',
46+
`sass-loader?includePaths[]=${inSrc('styles')}`
47+
]
4448
}
45-
)
46-
config.postcss = () => [autoprefixer, csswring]
49+
);
4750

48-
export default require(`./_${NODE_ENV}`)(config);
51+
export default (configName) => {
52+
return require(`./_${configName || NODE_ENV}`)(config);
53+
};

build/webpack/make-config.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import assign from 'object-assign';
22
import webpack from 'webpack';
3-
import { inProject, inSrc, inDist } from '../../lib/path';
4-
import { NODE_ENV, __DEV__, __PROD__ } from '../../lib/environment';
3+
import {
4+
NODE_ENV,
5+
inProject,
6+
inSrc,
7+
SRC_DIRNAME,
8+
__DEV__,
9+
__PROD__
10+
} from '../../config';
511

612
function makeDefaultConfig () {
713
const config = {
@@ -26,23 +32,25 @@ function makeDefaultConfig () {
2632
components : inSrc('components'),
2733
constants : inSrc('constants'),
2834
dispatchers : inSrc('dispatchers'),
35+
layouts : inSrc('layouts'),
2936
models : inSrc('models'),
3037
services : inSrc('services'),
3138
stores : inSrc('stores'),
32-
styles : inSrc('styles')
39+
styles : inSrc('styles'),
40+
views : inSrc('views')
3341
}
3442
},
3543
module : {
3644
preLoaders : [
3745
{
38-
test : [/\.js$/],
46+
test : /\.(js|jsx)?$/,
3947
loaders : ['eslint-loader'],
40-
exclude : /node_modules/
48+
include : inProject(SRC_DIRNAME)
4149
}
4250
],
4351
loaders : [{
44-
test : [/\.(js|jsx)?$/],
45-
include : inProject('app'),
52+
test : /\.(js|jsx)?$/,
53+
include : inProject(SRC_DIRNAME),
4654
loaders : ['babel?optional[]=runtime&stage=0']
4755
}]
4856
},

build/webpack/server/index.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import webpack from 'webpack';
22
import makeConfig from '../make-config';
3-
import { inSrc, inDist } from '../../../lib/path';
4-
import { NODE_ENV } from '../../../lib/environment';
3+
import { inSrc, inDist, NODE_ENV } from '../../../config';
54

65
const config = makeConfig({
7-
name : 'Server',
6+
name : 'server',
87
target : 'node',
98
entry : {
109
app : [
@@ -15,7 +14,8 @@ const config = makeConfig({
1514
filename : 'index.js',
1615
path : inDist('server'),
1716
libraryTarget : 'commonjs2'
18-
}
17+
},
18+
preloaders : []
1919
});
2020

2121
// ------------------------------------
@@ -28,4 +28,20 @@ config.plugins.push(
2828
})
2929
);
3030

31-
export default require(`./_${NODE_ENV}`)(config);
31+
// ------------------------------------
32+
// Server-Specific Loaders
33+
// ------------------------------------
34+
config.module.loaders.push(
35+
{
36+
test : /\.scss$/,
37+
loaders : [
38+
'css/locals?module&localIdentName=[name]__[local]___[hash:base64:5]',
39+
'autoprefixer?browsers=last 2 version',
40+
`sass-loader?includePaths[]=${inSrc('styles')}`
41+
]
42+
}
43+
);
44+
45+
export default (configName) => {
46+
return require(`./_${configName || NODE_ENV}`)(config);
47+
};

0 commit comments

Comments
 (0)