Skip to content
This repository was archived by the owner on Jun 3, 2019. It is now read-only.

Commit 0f0ca7d

Browse files
committed
Fixed tests, coverage and build
1 parent 61e34bf commit 0f0ca7d

File tree

10 files changed

+11906
-3025
lines changed

10 files changed

+11906
-3025
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
["env", { "targets": { "node": true } }],
1111
"stage-3",
1212
"react"
13+
],
14+
"plugins": [
15+
"syntax-dynamic-import"
1316
]
1417
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<p align='center'>A starter kit for universal react applications.</p>
55
</p>
66

7+
![Version](https://img.shields.io/github/package-json/v/ctrlplusb/react-universally.svg?style=flat-square) ![Downloads per month](https://img.shields.io/npm/dm/react-async-component.svg?style=flat-square) [![All Contributorss](https://img.shields.io/badge/all_contributors-20-orange.svg?style=flat-square)](#contributors) [![Dependencies](https://david-dm.org/ctrlplusb/react-universally.svg?style=flat-square)](https://david-dm.org/ctrlplusb/react-universally) [![devDependencies](https://david-dm.org/ctrlplusb/react-universally/dev-status.svg?style=flat-square)](https://david-dm.org/ctrlplusb/react-universally?type=dev)
8+
79
## About
810

911
This starter kit contains all the build tooling and configuration you need to kick off your next universal React project, whilst containing a minimal "project" set up allowing you to make your own architecture decisions (Redux/MobX etc).

config/values.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const values = {
2727
},
2828

2929
// The host on which the server should run.
30-
host: EnvVars.string('HOST', '0.0.0.0'),
30+
host: EnvVars.string('HOST', 'localhost'),
3131

3232
// The port on which the server should run.
3333
port: EnvVars.number('PORT', 1337),

internal/development/createVendorDLL.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ function createVendorDLL(bundleName, bundleConfig) {
3838

3939
function webpackConfigFactory() {
4040
return {
41+
// Force development mode as the dev server should only be ran while developing.
42+
mode: 'development',
4143
// We only use this for development, so lets always include source maps.
4244
devtool: 'inline-source-map',
4345
entry: {
@@ -94,7 +96,7 @@ function createVendorDLL(bundleName, bundleConfig) {
9496
level: 'warn',
9597
message: `Generating a new "${bundleName}" Vendor DLL for boosted development performance.
9698
97-
The Vendor DLL helps to speed up your development workflow by reducing Webpack build times. It does this by seperating Vendor DLLs from your primary bundles, thereby allowing Webpack to ignore them when having to rebuild your code for changes.
99+
The Vendor DLL helps to speed up your development workflow by reducing Webpack build times. It does this by seperating Vendor DLLs from your primary bundles, thereby allowing Webpack to ignore them when having to rebuild your code for changes.
98100
99101
We recommend that you add all your client bundle specific dependencies to the Vendor DLL configuration (within /config).`,
100102
});

internal/development/hotClientServer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class HotClientServer {
2323
quiet: true,
2424
noInfo: true,
2525
headers: {
26+
// Allow any host to connect to the webpack dev server
2627
'Access-Control-Allow-Origin': '*',
2728
},
2829
// Ensure that the public path is taken from the compiler webpack config

internal/development/hotNodeServer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class HotNodeServer {
8080

8181
compiler.plugin('done', stats => {
8282
this.serverCompiling = false;
83+
console.log('2. Done compiling');
8384

8485
if (this.disposing) {
8586
return;

internal/development/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import http from 'http';
2+
import openBrowser from 'react-dev-utils/openBrowser';
13
import chokidar from 'chokidar';
24
import { resolve as pathResolve } from 'path';
35
import appRootDir from 'app-root-dir';
6+
import config from '../../config/values';
47
import { log } from '../utils';
58

69
let HotDevelopment = require('./hotDevelopment').default;
@@ -12,6 +15,20 @@ const watcher = chokidar.watch([
1215
pathResolve(appRootDir.get(), 'config'),
1316
]);
1417

18+
// Wait until specific endpoint becomes responsive, then fire callback.
19+
const onResponsive = (hostname, port, cb) =>
20+
setTimeout(
21+
() =>
22+
http
23+
.get({ hostname, port, path: '/', agent: false }, cb)
24+
.on('error', () => onResponsive(hostname, port, cb)),
25+
1000,
26+
);
27+
28+
// Get host and port
29+
const host = config('host');
30+
const port = config('port');
31+
1532
watcher.on('ready', () => {
1633
watcher.on('change', () => {
1734
log({
@@ -37,6 +54,9 @@ watcher.on('ready', () => {
3754
devServer = new HotDevelopment();
3855
});
3956
});
57+
58+
// Wait until devServer is started.
59+
onResponsive(host, port, () => openBrowser(`http://${host}:${port}`));
4060
});
4161

4262
// If we receive a kill cmd then we will first try to dispose our listeners.

internal/webpack/configFactory.js

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import appRootDir from 'app-root-dir';
22
import AssetsPlugin from 'assets-webpack-plugin';
33
import ExtractTextPlugin from 'extract-text-webpack-plugin';
4+
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
45
import nodeExternals from 'webpack-node-externals';
56
import path from 'path';
67
import webpack from 'webpack';
@@ -18,7 +19,7 @@ import config from '../../config';
1819
* This function has been configured to support one "client/web" bundle, and any
1920
* number of additional "node" bundles (e.g. our "server"). You can define
2021
* additional node bundles by editing the project confuguration.
21-
*
22+
com
2223
* @param {Object} buildOptions - The build options.
2324
* @param {target} buildOptions.target - The bundle target (e.g 'clinet' || 'server').
2425
* @param {target} buildOptions.optimize - Build an optimised version of the bundle?
@@ -171,6 +172,41 @@ export default function webpackConfigFactory(buildOptions) {
171172
false,
172173
),
173174

175+
// Webpack 4 automatically runs UglifyPlugin and other optimization processes.
176+
// It can be configured here:
177+
optimization: {
178+
minimizer: ifProdClient([
179+
new UglifyJsPlugin({
180+
uglifyOptions: {
181+
ecma: 8,
182+
compress: {
183+
warnings: false,
184+
// Disabled because of an issue with Uglify breaking seemingly valid code:
185+
// https://github.com/facebook/create-react-app/issues/2376
186+
// Pending further investigation:
187+
// https://github.com/mishoo/UglifyJS2/issues/2011
188+
comparisons: false,
189+
},
190+
mangle: {
191+
safari10: true,
192+
},
193+
output: {
194+
comments: false,
195+
// Turned on because emoji and regex is not minified properly using default
196+
// https://github.com/facebook/create-react-app/issues/2488
197+
ascii_only: true,
198+
},
199+
},
200+
// Use multi-process parallel running to improve the build speed
201+
// Default number of concurrent runs: os.cpus().length - 1
202+
parallel: true,
203+
// Enable file caching
204+
cache: true,
205+
sourceMap: config('includeSourceMapsForOptimisedClientBundle'),
206+
}),
207+
]),
208+
},
209+
174210
resolve: {
175211
// These extensions are tried when resolving a file.
176212
extensions: config('bundleSrcTypes').map(ext => `.${ext}`),
@@ -223,11 +259,6 @@ export default function webpackConfigFactory(buildOptions) {
223259
}),
224260
),
225261

226-
// Implement webpack 3 scope hoisting that will remove function wrappers
227-
// around your modules you may see some small size improvements. However,
228-
// the significant improvement will be how fast the JavaScript loads in the browser.
229-
ifProdClient(new webpack.optimize.ModuleConcatenationPlugin()),
230-
231262
// These are process.env flags that you can use in your code in order to
232263
// have advanced control over what is included/excluded in your bundles.
233264
// For example you may only want certain parts of your code to be
@@ -291,35 +322,6 @@ export default function webpackConfigFactory(buildOptions) {
291322
// We need this plugin to enable hot reloading of our client.
292323
ifDevClient(() => new webpack.HotModuleReplacementPlugin()),
293324

294-
// For our production client we need to make sure we pass the required
295-
// configuration to ensure that the output is minimized/optimized.
296-
ifProdClient(
297-
() =>
298-
new webpack.LoaderOptionsPlugin({
299-
minimize: true,
300-
}),
301-
),
302-
303-
// For our production client we need to make sure we pass the required
304-
// configuration to ensure that the output is minimized/optimized.
305-
ifProdClient(
306-
() =>
307-
new webpack.optimize.UglifyJsPlugin({
308-
sourceMap: config('includeSourceMapsForOptimisedClientBundle'),
309-
compress: {
310-
screw_ie8: true,
311-
warnings: false,
312-
},
313-
mangle: {
314-
screw_ie8: true,
315-
},
316-
output: {
317-
comments: false,
318-
screw_ie8: true,
319-
},
320-
}),
321-
),
322-
323325
// For the production build of the client we need to extract the CSS into
324326
// CSS files.
325327
ifProdClient(

0 commit comments

Comments
 (0)