Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds vendor bundling #487

Merged
merged 7 commits into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
coverage
**/node_modules
e2e_tests/fixtures

**/build
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

## Master

### BREAKING CHANGES

- Adds vendor bundling [#487](https://github.com/NYTimes/kyt/pull/487)

## 0.5.5 - 05/02/17
- Fixes bug in IE11, moves 'react-hot-loader/patch' after 'babel-polyfill'.[#473](https://github.com/NYTimes/kyt/pull/473)
- Fixes history api for static starter-kyt [#468](https://github.com/NYTimes/kyt/pull/468)
Expand Down
5 changes: 5 additions & 0 deletions e2e_tests/tests/kyt-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ describe('kyt build', () => {
// Should copy static assets from src/public directory
expect(shell.test('-f', 'build/public/nothing.txt')).toBe(true);

// Should produce the manifest, main and vendor scripts
expect(shell.ls('build/public/manifest-*.js').code).toBe(0);
expect(shell.ls('build/public/main-*.js').code).toBe(0);
expect(shell.ls('build/public/vendor-*.js').code).toBe(0);

expect(output.code).toBe(0);
});

Expand Down
9 changes: 9 additions & 0 deletions packages/kyt-core/config/__tests__/webpack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@ const logger = {
warn: jest.fn(),
};

const path = {
join: jest.fn(),
resolve: jest.fn(),
};

const webpack = {
LoaderOptionsPlugin: jest.fn(),
optimize: {
UglifyJsPlugin: jest.fn(),
LimitChunkCountPlugin: jest.fn(),
CommonsChunkPlugin: jest.fn(),
AggressiveMergingPlugin: jest.fn(),
},
BannerPlugin: jest.fn(),
NoEmitOnErrorsPlugin: jest.fn(),
HotModuleReplacementPlugin: jest.fn(),
DefinePlugin: jest.fn(),
HashedModuleIdsPlugin: jest.fn(),
};

jest.setMock('shelljs', shell);
jest.setMock('path', path);
jest.setMock('kyt-utils/logger', logger);
jest.setMock('webpack', webpack);

Expand Down
13 changes: 9 additions & 4 deletions packages/kyt-core/config/webpack.dev.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// Development webpack config for client code

const webpack = require('webpack');
const AssetsPlugin = require('assets-webpack-plugin');
const WebpackAssetsManifest = require('webpack-assets-manifest');
const clone = require('lodash.clonedeep');
const path = require('path');
const { clientSrcPath, buildPath, assetsBuildPath } = require('kyt-utils/paths')();

const cssStyleLoaders = [
Expand Down Expand Up @@ -68,9 +69,13 @@ module.exports = (options) => {

new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),

new AssetsPlugin({
filename: options.clientAssetsFile,
path: buildPath,
new WebpackAssetsManifest({
output: path.join(buildPath, options.clientAssetsFile),
space: 2,
writeToDisk: true,
fileExtRegex: /\.\w{2,4}\.(?:map|gz)$|\.\w+$/i,
merge: false,
publicPath: options.publicPath,
}),

new webpack.HotModuleReplacementPlugin(),
Expand Down
30 changes: 26 additions & 4 deletions packages/kyt-core/config/webpack.prod.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const AssetsPlugin = require('assets-webpack-plugin');
const WebpackAssetsManifest = require('webpack-assets-manifest');
const { clientSrcPath, assetsBuildPath, buildPath } = require('kyt-utils/paths')();
const path = require('path');

const cssLoader = 'css-loader?modules&sourceMap&minimize&-autoprefixer&localIdentName=[name]-[local]--[hash:base64:5]!postcss-loader';

Expand Down Expand Up @@ -66,9 +67,30 @@ module.exports = options => ({
sourceMap: true,
}),

new AssetsPlugin({
filename: options.clientAssetsFile,
path: buildPath,
new WebpackAssetsManifest({
output: path.join(buildPath, options.clientAssetsFile),
space: 2,
writeToDisk: true,
fileExtRegex: /\.\w{2,4}\.(?:map|gz)$|\.\w+$/i,
merge: false,
publicPath: options.publicPath,
}),

// Modules should get deterministic ids so that they don't change between builds
new webpack.HashedModuleIdsPlugin(),

// Extract all 3rd party modules into a separate chunk
// Only include vendor modules as needed,
// https://github.com/webpack/webpack/issues/2372#issuecomment-213149173
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: ({ resource }) => /node_modules/.test(resource),
}),

// Generate a 'manifest' chunk to be inlined
new webpack.optimize.CommonsChunkPlugin({ name: 'manifest' }),

// Merge bundles that would otherwise be negligibly small
new webpack.optimize.AggressiveMergingPlugin(),
],
});
2 changes: 1 addition & 1 deletion packages/kyt-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"node": ">=6.1.0"
},
"dependencies": {
"assets-webpack-plugin": "3.5.1",
"autoprefixer": "7.1.1",
"babel-cli": "6.18.0",
"babel-core": "6.18.0",
Expand Down Expand Up @@ -65,6 +64,7 @@
"temp": "0.8.3",
"url-loader": "0.5.8",
"webpack": "2.6.0",
"webpack-assets-manifest": "0.6.2",
"webpack-dev-middleware": "1.10.2",
"webpack-dev-server": "2.4.5",
"webpack-hot-middleware": "2.18.0",
Expand Down
106 changes: 35 additions & 71 deletions packages/kyt-core/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ acorn@^3.0.4:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"

acorn@^4.0.3, acorn@^4.0.4:
version "4.0.11"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.11.tgz#edcda3bd937e7556410d42ed5860f67399c794c0"
version "4.0.13"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787"

acorn@^5.0.0, acorn@^5.0.1:
version "5.0.3"
Expand Down Expand Up @@ -227,16 +227,6 @@ assert@^1.1.1:
dependencies:
util "0.10.3"

assets-webpack-plugin@3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/assets-webpack-plugin/-/assets-webpack-plugin-3.5.1.tgz#931ce0d66d42e88ed5e7f18d65522943c57a387d"
dependencies:
camelcase "^1.2.1"
escape-string-regexp "^1.0.3"
lodash.assign "^3.2.0"
lodash.merge "^3.3.2"
mkdirp "^0.5.1"

ast-types-flow@0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/ast-types-flow/-/ast-types-flow-0.0.7.tgz#f70b735c6bca1a5c9c22d982c3e39e7feba3bdad"
Expand Down Expand Up @@ -1085,7 +1075,7 @@ camelcase-keys@^2.0.0:
camelcase "^2.0.0"
map-obj "^1.0.0"

camelcase@^1.0.2, camelcase@^1.2.1:
camelcase@^1.0.2:
version "1.2.1"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39"

Expand Down Expand Up @@ -1125,7 +1115,7 @@ center-align@^0.1.1:
align-text "^0.1.3"
lazy-cache "^1.0.3"

chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
chalk@^1.0, chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
dependencies:
Expand Down Expand Up @@ -1964,7 +1954,7 @@ escape-html@~1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"

escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.3, escape-string-regexp@^1.0.5:
escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"

Expand Down Expand Up @@ -3698,14 +3688,6 @@ locate-path@^2.0.0:
p-locate "^2.0.0"
path-exists "^3.0.0"

lodash._arraycopy@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._arraycopy/-/lodash._arraycopy-3.0.0.tgz#76e7b7c1f1fb92547374878a562ed06a3e50f6e1"

lodash._arrayeach@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._arrayeach/-/lodash._arrayeach-3.0.0.tgz#bab156b2a90d3f1bbd5c653403349e5e5933ef9e"

lodash._baseassign@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e"
Expand All @@ -3717,10 +3699,6 @@ lodash._basecopy@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36"

lodash._basefor@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash._basefor/-/lodash._basefor-3.0.3.tgz#7550b4e9218ef09fad24343b612021c79b4c20c2"

lodash._bindcallback@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
Expand All @@ -3741,7 +3719,7 @@ lodash._isiterateecall@^3.0.0:
version "3.0.9"
resolved "https://registry.yarnpkg.com/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz#5203ad7ba425fae842460e696db9cf3e6aac057c"

lodash.assign@^3.0.0, lodash.assign@^3.2.0:
lodash.assign@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-3.2.0.tgz#3ce9f0234b4b2223e296b8fa0ac1fee8ebca64fa"
dependencies:
Expand Down Expand Up @@ -3772,6 +3750,14 @@ lodash.defaults@^3.1.2:
lodash.assign "^3.0.0"
lodash.restparam "^3.0.0"

lodash.find@^4.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.find/-/lodash.find-4.6.0.tgz#cb0704d47ab71789ffa0de8b97dd926fb88b13b1"

lodash.get@^4.0:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"

lodash.isarguments@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a"
Expand All @@ -3780,18 +3766,6 @@ lodash.isarray@^3.0.0:
version "3.0.4"
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55"

lodash.isplainobject@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-3.2.0.tgz#9a8238ae16b200432960cd7346512d0123fbf4c5"
dependencies:
lodash._basefor "^3.0.0"
lodash.isarguments "^3.0.0"
lodash.keysin "^3.0.0"

lodash.istypedarray@^3.0.0:
version "3.0.6"
resolved "https://registry.yarnpkg.com/lodash.istypedarray/-/lodash.istypedarray-3.0.6.tgz#c9a477498607501d8e8494d283b87c39281cef62"

lodash.keys@^3.0.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a"
Expand All @@ -3800,37 +3774,18 @@ lodash.keys@^3.0.0:
lodash.isarguments "^3.0.0"
lodash.isarray "^3.0.0"

lodash.keysin@^3.0.0:
version "3.0.8"
resolved "https://registry.yarnpkg.com/lodash.keysin/-/lodash.keysin-3.0.8.tgz#22c4493ebbedb1427962a54b445b2c8a767fb47f"
dependencies:
lodash.isarguments "^3.0.0"
lodash.isarray "^3.0.0"
lodash.keys@^4.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-4.2.0.tgz#a08602ac12e4fb83f91fc1fb7a360a4d9ba35205"

lodash.memoize@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"

lodash.merge@4.6.0:
lodash.merge@4.6.0, lodash.merge@^4.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.0.tgz#69884ba144ac33fe699737a6086deffadd0f89c5"

lodash.merge@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-3.3.2.tgz#0d90d93ed637b1878437bb3e21601260d7afe994"
dependencies:
lodash._arraycopy "^3.0.0"
lodash._arrayeach "^3.0.0"
lodash._createassigner "^3.0.0"
lodash._getnative "^3.0.0"
lodash.isarguments "^3.0.0"
lodash.isarray "^3.0.0"
lodash.isplainobject "^3.0.0"
lodash.istypedarray "^3.0.0"
lodash.keys "^3.0.0"
lodash.keysin "^3.0.0"
lodash.toplainobject "^3.0.0"

lodash.mergewith@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.0.tgz#150cf0a16791f5903b8891eab154609274bdea55"
Expand All @@ -3839,6 +3794,10 @@ lodash.once@4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac"

lodash.pick@^4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3"

lodash.pickby@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff"
Expand All @@ -3851,13 +3810,6 @@ lodash.tail@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.tail/-/lodash.tail-4.1.1.tgz#d2333a36d9e7717c8ad2f7cacafec7c32b444664"

lodash.toplainobject@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash.toplainobject/-/lodash.toplainobject-3.0.0.tgz#28790ad942d293d78aa663a07ecf7f52ca04198d"
dependencies:
lodash._basecopy "^3.0.0"
lodash.keysin "^3.0.0"

lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
Expand Down Expand Up @@ -4046,7 +3998,7 @@ mixin-object@^2.0.1:
for-in "^0.1.3"
is-extendable "^0.1.1"

mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
Expand Down Expand Up @@ -6289,6 +6241,18 @@ webidl-conversions@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.1.tgz#8015a17ab83e7e1b311638486ace81da6ce206a0"

webpack-assets-manifest@0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/webpack-assets-manifest/-/webpack-assets-manifest-0.6.2.tgz#1f8dd38a2d132474ce26e7d37dc894ba6ddf4b4f"
dependencies:
chalk "^1.0"
lodash.find "^4.0"
lodash.get "^4.0"
lodash.keys "^4.0"
lodash.merge "^4.0"
lodash.pick "^4.0"
mkdirp "^0.5"

webpack-dev-middleware@1.10.2, webpack-dev-middleware@^1.10.2:
version "1.10.2"
resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-1.10.2.tgz#2e252ce1dfb020dbda1ccb37df26f30ab014dbd1"
Expand Down
4 changes: 2 additions & 2 deletions packages/kyt-starter-static/starter-src/src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import App from '../components/App';
// https://webpack.js.org/guides/migrating/#code-splitting-with-es2015

const importHome = (nextState, cb) => {
import('../components/Home')
import(/* webpackChunkName: "home" */'../components/Home')
.then(module => cb(null, module.default))
.catch((e) => { throw e; });
};

const importTools = (nextState, cb) => {
import('../components/Tools')
import(/* webpackChunkName: "tools" */'../components/Tools')
.then(module => cb(null, module.default))
.catch((e) => { throw e; });
};
Expand Down
Loading