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

Commit 88370f2

Browse files
committed
Webpack 4 changes
2 parents d1a41e8 + 835de07 commit 88370f2

File tree

8 files changed

+3210
-1061
lines changed

8 files changed

+3210
-1061
lines changed
File renamed without changes.

internal/development/hotClientServer.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import express from 'express';
22
import createWebpackMiddleware from 'webpack-dev-middleware';
33
import createWebpackHotMiddleware from 'webpack-hot-middleware';
44
import ListenerManager from './listenerManager';
5-
import config from '../../config';
65
import { log } from '../utils';
76

87
class HotClientServer {
@@ -24,7 +23,7 @@ class HotClientServer {
2423
quiet: true,
2524
noInfo: true,
2625
headers: {
27-
'Access-Control-Allow-Origin': `http://${config('host')}:${config('port')}`,
26+
'Access-Control-Allow-Origin': '*',
2827
},
2928
// Ensure that the public path is taken from the compiler webpack config
3029
// as it will have been created as an absolute path to avoid conflicts
@@ -47,12 +46,13 @@ class HotClientServer {
4746
});
4847
});
4948

50-
compiler.plugin('done', (stats) => {
49+
compiler.plugin('done', stats => {
5150
if (stats.hasErrors()) {
5251
log({
5352
title: 'client',
5453
level: 'error',
55-
message: 'Build failed, please check the console for more information.',
54+
message:
55+
'Build failed, please check the console for more information.',
5656
notify: true,
5757
});
5858
console.error(stats.toString());
@@ -70,7 +70,9 @@ class HotClientServer {
7070
dispose() {
7171
this.webpackDevMiddleware.close();
7272

73-
return this.listenerManager ? this.listenerManager.dispose() : Promise.resolve();
73+
return this.listenerManager
74+
? this.listenerManager.dispose()
75+
: Promise.resolve();
7476
}
7577
}
7678

internal/webpack/configFactory.js

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import ExtractTextPlugin from 'extract-text-webpack-plugin';
44
import nodeExternals from 'webpack-node-externals';
55
import path from 'path';
66
import webpack from 'webpack';
7-
import WebpackMd5Hash from 'webpack-md5-hash';
87

98
import { happyPackPlugin, log } from '../utils';
109
import { ifElse } from '../../shared/utils/logic';
@@ -55,15 +54,17 @@ export default function webpackConfigFactory(buildOptions) {
5554
const bundleConfig =
5655
isServer || isClient
5756
? // This is either our "server" or "client" bundle.
58-
config(['bundles', target])
57+
config(['bundles', target])
5958
: // Otherwise it must be an additional node bundle.
60-
config(['additionalNodeBundles', target]);
59+
config(['additionalNodeBundles', target]);
6160

6261
if (!bundleConfig) {
6362
throw new Error('No bundle configuration exists for target:', target);
6463
}
6564

6665
let webpackConfig = {
66+
// Webpack Mode
67+
mode: ifDev('development', 'production'),
6768
// Define our entry chunks for our bundle.
6869
entry: {
6970
// We name our entry files "index" as it makes it easier for us to
@@ -80,9 +81,9 @@ export default function webpackConfigFactory(buildOptions) {
8081
// Required to support hot reloading of our client.
8182
ifDevClient(
8283
() =>
83-
`webpack-hot-middleware/client?reload=true&path=http://${config('host')}:${config(
84-
'clientDevServerPort',
85-
)}/__webpack_hmr`,
84+
`webpack-hot-middleware/client?reload=true&path=http://${config(
85+
'host',
86+
)}:${config('clientDevServerPort')}/__webpack_hmr`,
8687
),
8788

8889
// The source entry file for the bundle.
@@ -127,9 +128,9 @@ export default function webpackConfigFactory(buildOptions) {
127128

128129
target: isClient
129130
? // Only our client bundle will target the web as a runtime.
130-
'web'
131+
'web'
131132
: // Any other bundle must be targetting node as a runtime.
132-
'node',
133+
'node',
133134

134135
// Ensure that webpack polyfills the following node features for use
135136
// within any bundles that are targetting node as a runtime. This will be
@@ -177,7 +178,7 @@ export default function webpackConfigFactory(buildOptions) {
177178
// This is required for the modernizr-loader
178179
// @see https://github.com/peerigon/modernizr-loader
179180
alias: {
180-
modernizr$: path.resolve(appRootDir.get(), './.modernizrrc'),
181+
modernizr$: path.resolve(appRootDir.get(), './.modernizrrc.json'),
181182
},
182183
},
183184

@@ -227,13 +228,6 @@ export default function webpackConfigFactory(buildOptions) {
227228
// the significant improvement will be how fast the JavaScript loads in the browser.
228229
ifProdClient(new webpack.optimize.ModuleConcatenationPlugin()),
229230

230-
// We use this so that our generated [chunkhash]'s are only different if
231-
// the content for our respective chunks have changed. This optimises
232-
// our long term browser caching strategy for our client bundle, avoiding
233-
// cases where browsers end up having to download all the client chunks
234-
// even though 1 or 2 may have only changed.
235-
ifClient(() => new WebpackMd5Hash()),
236-
237231
// These are process.env flags that you can use in your code in order to
238232
// have advanced control over what is included/excluded in your bundles.
239233
// For example you may only want certain parts of your code to be
@@ -408,6 +402,8 @@ export default function webpackConfigFactory(buildOptions) {
408402
// React that the subtree hasn’t changed so React can completely
409403
// skip it when reconciling.
410404
ifProd('transform-react-constant-elements'),
405+
// Add syntax dynamic import for direct webpack `import()` support
406+
'syntax-dynamic-import',
411407
].filter(x => x != null),
412408
},
413409
buildOptions,
@@ -452,7 +448,9 @@ export default function webpackConfigFactory(buildOptions) {
452448
// details on what loader is being implemented.
453449
loader: 'happypack/loader?id=happypack-javascript',
454450
include: removeNil([
455-
...bundleConfig.srcPaths.map(srcPath => path.resolve(appRootDir.get(), srcPath)),
451+
...bundleConfig.srcPaths.map(srcPath =>
452+
path.resolve(appRootDir.get(), srcPath),
453+
),
456454
ifProdClient(path.resolve(appRootDir.get(), 'src/html')),
457455
]),
458456
},
@@ -501,10 +499,6 @@ export default function webpackConfigFactory(buildOptions) {
501499
test: /\.modernizrrc.js$/,
502500
loader: 'modernizr-loader',
503501
}),
504-
ifClient({
505-
test: /\.modernizrrc(\.json)?$/,
506-
loader: 'modernizr-loader!json-loader',
507-
}),
508502

509503
// ASSETS (Images/Fonts/etc)
510504
// This is bound to our server/client bundles as we only expect to be
@@ -520,12 +514,12 @@ export default function webpackConfigFactory(buildOptions) {
520514
// paths used on the client.
521515
publicPath: isDev
522516
? // When running in dev mode the client bundle runs on a
523-
// seperate port so we need to put an absolute path here.
524-
`http://${config('host')}:${config('clientDevServerPort')}${config(
525-
'bundles.client.webPath',
526-
)}`
517+
// seperate port so we need to put an absolute path here.
518+
`http://${config('host')}:${config(
519+
'clientDevServerPort',
520+
)}${config('bundles.client.webPath')}`
527521
: // Otherwise we just use the configured web path for the client.
528-
config('bundles.client.webPath'),
522+
config('bundles.client.webPath'),
529523
// We only emit files when building a web bundle, for the server
530524
// bundle we only care about the file loader being able to create
531525
// the correct asset URLs.

0 commit comments

Comments
 (0)