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

Commit b7a0757

Browse files
committed
fixed configuration for long term caching
in context of the acticle linked in facebook#2328
1 parent 812e209 commit b7a0757

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

packages/react-scripts/config/webpack.config.prod.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const autoprefixer = require('autoprefixer');
1414
const path = require('path');
1515
const fs = require('fs');
1616
const webpack = require('webpack');
17-
const WebpackMd5Hash = require('webpack-md5-hash');
17+
const NameAllModulesPlugin = require('name-all-modules-plugin');
1818
const HtmlWebpackPlugin = require('html-webpack-plugin');
1919
const ExtractTextPlugin = require('extract-text-webpack-plugin');
2020
const ManifestPlugin = require('webpack-manifest-plugin');
@@ -264,6 +264,41 @@ module.exports = {
264264
],
265265
},
266266
plugins: [
267+
// configuration for vendor splitting and long term caching
268+
// more info: https://medium.com/webpack/predictable-long-term-caching-with-webpack-d3eee1d3fa31
269+
new webpack.NamedModulesPlugin(),
270+
new webpack.NamedChunksPlugin(chunk => {
271+
if (chunk.name) {
272+
return chunk.name;
273+
}
274+
return chunk.modules
275+
.map(m => path.relative(m.context, m.request))
276+
.join('_');
277+
}),
278+
new webpack.optimize.CommonsChunkPlugin(
279+
// Check if vendor file exists, if it does,
280+
// generate a seperate chucks for vendor
281+
// else don't generate any common chunck
282+
checkIfVendorFileExists
283+
? {
284+
name: 'vendor',
285+
minChunks: Infinity,
286+
}
287+
: { names: [] }
288+
),
289+
// We need to extract out the runtime into a separate manifest file.
290+
// more info: https://webpack.js.org/guides/code-splitting-libraries/#manifest-file
291+
new webpack.optimize.CommonsChunkPlugin(
292+
// Check if vendor file exists, if it does,
293+
// generate a seperate chucks for manifest file
294+
// else don't generate any common chunck
295+
checkIfVendorFileExists
296+
? {
297+
name: 'manifest',
298+
}
299+
: { names: [] }
300+
),
301+
new NameAllModulesPlugin(),
267302
// Makes some environment variables available in index.html.
268303
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
269304
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
@@ -292,17 +327,6 @@ module.exports = {
292327
// It is absolutely essential that NODE_ENV was set to production here.
293328
// Otherwise React will be compiled in the very slow development mode.
294329
new webpack.DefinePlugin(env.stringified),
295-
// We need to extract out the runtime into a separate manifest file.
296-
// more info: https://webpack.js.org/guides/code-splitting-libraries/#manifest-file
297-
new webpack.optimize.CommonsChunkPlugin({
298-
// Check if vendor file exists, if it does,
299-
// generate a seperate chucks for vendor and manifest file
300-
// else don't generate any common chunck
301-
names: checkIfVendorFileExists ? ['vendor', 'manifest'] : [],
302-
}),
303-
// Need this plugin for deterministic hashing
304-
// until this issue is resolved: https://github.com/webpack/webpack/issues/1315
305-
new WebpackMd5Hash(),
306330
// Minify the code.
307331
new webpack.optimize.UglifyJsPlugin({
308332
compress: {

packages/react-scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"fs-extra": "3.0.1",
4747
"html-webpack-plugin": "2.28.0",
4848
"jest": "20.0.3",
49+
"name-all-modules-plugin": "^1.0.1",
4950
"object-assign": "4.1.1",
5051
"postcss-flexbugs-fixes": "3.0.0",
5152
"postcss-loader": "2.0.5",
@@ -58,7 +59,6 @@
5859
"webpack": "2.5.1",
5960
"webpack-dev-server": "2.4.5",
6061
"webpack-manifest-plugin": "1.1.0",
61-
"webpack-md5-hash": "0.0.5",
6262
"whatwg-fetch": "2.0.3"
6363
},
6464
"devDependencies": {

0 commit comments

Comments
 (0)