Skip to content
This repository has been archived by the owner on Dec 27, 2018. It is now read-only.

Commit

Permalink
Long term caching - separate chunks for app, vendor libs, webpack man…
Browse files Browse the repository at this point in the history
  • Loading branch information
robatwilliams committed Dec 3, 2017
1 parent f84e206 commit 0d3f16f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Build:
* Webpack
* Minification
* Tree-shaking
* App/vendor code split
* Long-term caching
* Bundle analysis
* Source maps (TypeScript, styles)

Expand Down
17 changes: 13 additions & 4 deletions config/webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');

const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const rootPath = path.resolve(__dirname, '../');
Expand Down Expand Up @@ -40,11 +41,19 @@ module.exports = {
]
},

output: {
filename: '[name].bundle.js'
},

plugins: [
// Vendor chunk for libraries, separate from application code
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: (module, count) => module.context.includes('node_modules')
}),

// Webpack runtime & manifest chunk (needs to be the last CommonsChunk)
new webpack.optimize.CommonsChunkPlugin({
name: 'runtime-manifest',
minChunks: Infinity // ensures no modules go in the chunk
}),

// Creates index.html
new HtmlWebpackPlugin({
favicon: './src/favicon.ico',
Expand Down
6 changes: 5 additions & 1 deletion config/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ module.exports = Object.assign({}, common, {

// Cheaper alternative to eval-source-map, since column mappings (for inline breakpoints) are
// broken in Chrome 62 anyway - even for the most basic standalone tsc-only or webpack-only examples.
devtool: 'cheap-module-eval-source-map'
devtool: 'cheap-module-eval-source-map',

output: {
filename: '[name].js'
}
});
5 changes: 3 additions & 2 deletions config/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const rootPath = path.resolve(__dirname, '../');
module.exports = Object.assign({}, common, {
devtool: 'source-map',

output: Object.assign({}, common.output, {
output: {
filename: '[name].[chunkhash].js',
path: path.resolve(rootPath, 'dist')
}),
},

performance: {
// Prevent limit breaches going unnoticed
Expand Down
11 changes: 0 additions & 11 deletions docs/backlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,9 @@ Testing:
* Workflows - debugging, watching

Build:
* App/vendor code split
<details>
https://webpack.js.org/concepts/entry-points/#separate-app-and-vendor-entries
https://webpack.js.org/guides/build-performance/#dlls
</details>
* Compression
* Continuous integration target (build, check, & test) & server config
* ES6 build for modern browsers
* Long-term caching
<details>
https://medium.com/webpack/predictable-long-term-caching-with-webpack-d3eee1d3fa31
https://survivejs.com/webpack/optimizing/separating-manifest/
https://webpack.js.org/guides/build-performance/#minimal-entry-chunk
</details>

Development:
* Hot reloading
Expand Down

0 comments on commit 0d3f16f

Please sign in to comment.