Skip to content

Commit 7ce1a11

Browse files
committed
Build with node API rather than CLI - supports builds on Windows
1 parent 52fe798 commit 7ce1a11

File tree

5 files changed

+151
-64
lines changed

5 files changed

+151
-64
lines changed

package.json

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,48 +34,69 @@
3434
"dev:start": "yarn run dev:start:client & yarn run dev:start:server",
3535
"dev:start:server": {
3636
"command": "yarn run nodemon server",
37-
"env": { "NODE_ENV": "development" }
37+
"env": {
38+
"NODE_ENV": "development"
39+
}
3840
},
3941
"dev:start:client": {
40-
"command": "yarn run babel-node webpack/development.hot",
41-
"env": { "NODE_ENV": "development" }
42+
"command": "yarn run babel-node -- webpack/development.hot",
43+
"env": {
44+
"NODE_ENV": "development"
45+
}
4246
},
4347
"dev:build": {
44-
"command": "$(yarn bin)/babel-node $(yarn bin)/webpack --progress --colors --display-error-details --config webpack/development.js",
45-
"env": { "NODE_ENV": "development" }
48+
"command": "yarn run babel-node -- ./script/build webpack/development.js",
49+
"env": {
50+
"NODE_ENV": "development"
51+
}
4652
},
4753
"prod:build": {
48-
"command": "$(yarn bin)/babel-node $(yarn bin)/webpack -p --optimize-dedupe --config webpack/production.js",
49-
"env": { "NODE_ENV": "production" }
54+
"command": "yarn run babel-node -- ./script/build webpack/production.js",
55+
"env": {
56+
"NODE_ENV": "production"
57+
}
5058
},
5159
"prod:start": {
5260
"command": "pm2 start server --name='universal-react-redux'",
53-
"env": { "NODE_ENV": "production" }
61+
"env": {
62+
"NODE_ENV": "production"
63+
}
5464
},
5565
"test": {
5666
"command": "yarn run mocha --recursive --compilers js:babel-register",
57-
"env": { "NODE_ENV": "test" }
67+
"env": {
68+
"NODE_ENV": "test"
69+
}
5870
},
5971
"test:all": {
6072
"command": "yarn run mocha --recursive --compilers js:babel-register $(find . -path ./node_modules -prune -o -name '*.test.js' -print)",
61-
"env": { "NODE_ENV": "test" }
73+
"env": {
74+
"NODE_ENV": "test"
75+
}
6276
},
6377
"test:watch": {
6478
"command": "yarn run test -- --watch",
65-
"env": { "NODE_ENV": "test" }
79+
"env": {
80+
"NODE_ENV": "test"
81+
}
6682
},
6783
"test:all:watch": {
6884
"command": "yarn run test:all -- --watch",
69-
"env": { "NODE_ENV": "test" }
85+
"env": {
86+
"NODE_ENV": "test"
87+
}
7088
},
7189
"lint": {
7290
"command": "yarn run eslint --ext .js,.jsx .",
73-
"env": { "NODE_ENV": "test" }
91+
"env": {
92+
"NODE_ENV": "test"
93+
}
7494
}
7595
},
7696
"devDependencies": {
7797
"babel-eslint": "7.1.1",
7898
"better-npm-run": "^0.0.13",
99+
"debug": "^2.6.0",
79100
"eslint": "3.11.1",
80101
"eslint-loader": "1.6.1",
81102
"eslint-plugin-react": "6.7.1",
@@ -139,7 +160,7 @@
139160
"serve-static": "1.11.1",
140161
"style-loader": "0.13.1",
141162
"url-loader": "0.5.7",
142-
"webpack": "2.1.0-beta.27",
163+
"webpack": "2.1.0-beta.28",
143164
"webpack-isomorphic-tools": "2.6.4"
144165
}
145166
}

script/build.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import webpack from 'webpack';
2+
import ProgressPlugin from 'webpack/lib/ProgressPlugin';
3+
4+
const args = process.argv.splice(2);
5+
const configFilePath = `${__dirname}/../${args[0]}`;
6+
const debug = require('debug')(args[0]);
7+
const configFile = require(configFilePath).default;
8+
const compiler = webpack(configFile);
9+
10+
const handleSoftErrors = (errors) => {
11+
debug('There were some errors with compilation.');
12+
debug(errors);
13+
};
14+
15+
const handleWarnings = (warnings) => {
16+
debug('There were some warnings with compilation.');
17+
debug(warnings);
18+
};
19+
20+
compiler.apply(new ProgressPlugin({ profile: true }));
21+
22+
compiler.run((err, stats) => {
23+
if (err || stats.hasErrors()) {
24+
debug('There was a fatal error with webpack.');
25+
debug(err);
26+
return;
27+
}
28+
29+
const jsonStats = stats.toJson();
30+
31+
if (jsonStats.errors.length > 0) {
32+
return handleSoftErrors(jsonStats.errors);
33+
}
34+
35+
if (jsonStats.warnings.length > 0) {
36+
return handleWarnings(jsonStats.warnings);
37+
}
38+
});

webpack/development.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ export default {
4040
...baseConfig.plugins,
4141
...plugins
4242
],
43-
module: Object.assign({}, baseConfig.module, {
43+
module: { ...baseConfig.module, ...{
4444
rules: [
4545
...baseConfig.module.rules,
4646
...loaders
4747
]
48-
})
48+
}}
4949
};

webpack/production.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,25 @@ const loaders = [
3535
})
3636
},
3737
{
38-
test: /\.js$/,
38+
test: /\.jsx$|\.js$/,
3939
loader: 'babel-loader',
40-
rules: ['babel'],
4140
exclude: /node_modules/
4241
}
4342
];
4443

4544
export default {
4645
...baseConfig,
47-
output: Object.assign({}, baseConfig.output, {
46+
output: { ...baseConfig.output, ...{
4847
filename: '[name].[hash].js'
49-
}),
48+
}},
5049
plugins: [
5150
...baseConfig.plugins,
5251
...plugins
5352
],
54-
module: Object.assign({}, baseConfig.module, {
53+
module: { ...baseConfig.module, ...{
5554
rules: [
5655
...baseConfig.module.rules,
5756
...loaders
5857
]
59-
})
58+
}}
6059
};

0 commit comments

Comments
 (0)