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

[optimizer] More aggressive chunking of common/vendor code #15816

Merged
merged 3 commits into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 15 additions & 9 deletions src/optimize/base_optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { writeFile } from 'fs';
import Boom from 'boom';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import webpack from 'webpack';
import CommonsChunkPlugin from 'webpack/lib/optimize/CommonsChunkPlugin';
import DefinePlugin from 'webpack/lib/DefinePlugin';
import UglifyJsPlugin from 'webpack/lib/optimize/UglifyJsPlugin';
import NoEmitOnErrorsPlugin from 'webpack/lib/NoEmitOnErrorsPlugin';
import Stats from 'webpack/lib/Stats';
import webpackMerge from 'webpack-merge';

Expand Down Expand Up @@ -98,6 +94,8 @@ export default class BaseOptimizer {
});
}

const nodeModulesPath = fromRoot('node_modules');

/**
* Adds a cache loader if we're running in dev mode. The reason we're not adding
* the cache-loader when running in production mode is that it creates cache
Expand Down Expand Up @@ -141,12 +139,20 @@ export default class BaseOptimizer {
allChunks: true
}),

new CommonsChunkPlugin({
new webpack.optimize.CommonsChunkPlugin({
name: 'commons',
filename: 'commons.bundle.js'
filename: 'commons.bundle.js',
minChunks: 2,
}),

new webpack.optimize.CommonsChunkPlugin({
name: 'vendors',
filename: 'vendors.bundle.js',
// only combine node_modules from Kibana
minChunks: module => module.context && module.context.indexOf(nodeModulesPath) !== -1
}),

new NoEmitOnErrorsPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
],

module: {
Expand Down Expand Up @@ -233,12 +239,12 @@ export default class BaseOptimizer {

return webpackMerge(commonConfig, {
plugins: [
new DefinePlugin({
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': '"production"'
}
}),
new UglifyJsPlugin({
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
Expand Down
3 changes: 3 additions & 0 deletions src/ui/ui_render/views/ui_app.jade
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ block content
return anchor.href;
}
var files = [
bundleFile('vendors.style.css'),
bundleFile('commons.style.css'),
bundleFile('#{app.getId()}.style.css'),

bundleFile('vendors.bundle.js'),
bundleFile('commons.bundle.js'),
bundleFile('#{app.getId()}.bundle.js')
];
Expand Down
6 changes: 6 additions & 0 deletions tasks/config/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ module.exports = function (grunt) {

// list of files / patterns to load in the browser
files: [
'http://localhost:5610/bundles/vendors.bundle.js',
'http://localhost:5610/bundles/commons.bundle.js',
'http://localhost:5610/bundles/tests.bundle.js',

'http://localhost:5610/bundles/vendors.style.css',
'http://localhost:5610/bundles/commons.style.css',
'http://localhost:5610/bundles/tests.style.css'
],
Expand Down Expand Up @@ -126,8 +129,11 @@ module.exports = function (grunt) {
singleRun: true,
options: {
files: [
'http://localhost:5610/bundles/vendors.bundle.js',
'http://localhost:5610/bundles/commons.bundle.js',
`http://localhost:5610/bundles/tests.bundle.js?shards=${TOTAL_CI_SHARDS}&shard_num=${n}`,

'http://localhost:5610/bundles/vendors.style.css',
'http://localhost:5610/bundles/commons.style.css',
'http://localhost:5610/bundles/tests.style.css'
]
Expand Down