added profiling capability and Commons chunk
This commit is contained in:
parent
ae91063fe6
commit
37b1c3a5a1
|
@ -5,6 +5,7 @@ let write = require('fs').writeFileSync;
|
|||
let webpack = require('webpack');
|
||||
let DirectoryNameAsMain = require('webpack-directory-name-as-main');
|
||||
let ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
var CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
|
||||
|
||||
let utils = require('requirefrom')('src/utils');
|
||||
let fromRoot = utils('fromRoot');
|
||||
|
@ -15,6 +16,7 @@ class BaseOptimizer {
|
|||
this.env = opts.env;
|
||||
this.bundles = opts.bundles;
|
||||
this.sourceMaps = opts.sourceMaps || false;
|
||||
this.profile = opts.profile || false;
|
||||
}
|
||||
|
||||
async initCompiler() {
|
||||
|
@ -29,6 +31,7 @@ class BaseOptimizer {
|
|||
entry: this.bundles.toWebpackEntries(),
|
||||
|
||||
devtool: this.sourceMaps ? '#source-map' : false,
|
||||
profile: this.profile || false,
|
||||
|
||||
output: {
|
||||
path: this.env.workingDir,
|
||||
|
@ -46,7 +49,8 @@ class BaseOptimizer {
|
|||
new webpack.optimize.DedupePlugin(),
|
||||
new ExtractTextPlugin('[name].style.css', {
|
||||
allChunks: true
|
||||
})
|
||||
}),
|
||||
new CommonsChunkPlugin('commons.bundle.js'),
|
||||
],
|
||||
|
||||
module: {
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
let { fromNode } = require('bluebird');
|
||||
let { writeFile } = require('fs');
|
||||
|
||||
let BaseOptimizer = require('./BaseOptimizer');
|
||||
let fromRoot = require('../utils/fromRoot');
|
||||
|
||||
module.exports = class FsOptimizer extends BaseOptimizer {
|
||||
async run() {
|
||||
await this.initCompiler();
|
||||
|
||||
await fromNode(cb => {
|
||||
let stats = await fromNode(cb => {
|
||||
this.compiler.run((err, stats) => {
|
||||
if (err || !stats) return cb(err);
|
||||
|
||||
|
@ -20,6 +23,17 @@ module.exports = class FsOptimizer extends BaseOptimizer {
|
|||
});
|
||||
});
|
||||
|
||||
if (this.profile) {
|
||||
await fromNode(cb => {
|
||||
writeFile(
|
||||
fromRoot('webpackstats.json'),
|
||||
JSON.stringify(stats.toJson()),
|
||||
{ encoding: 'utf8' },
|
||||
cb
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
this.compiler = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@ module.exports = async (kbnServer, server, config) => {
|
|||
let optimizer = new FsOptimizer({
|
||||
env: bundles.env,
|
||||
bundles: bundles,
|
||||
sourceMaps: config.get('optimize.sourceMaps')
|
||||
sourceMaps: config.get('optimize.sourceMaps'),
|
||||
profile: config.get('optimize.profile')
|
||||
});
|
||||
|
||||
server.exposeStaticDir('/bundles/{path*}', bundles.env.workingDir);
|
||||
|
|
|
@ -4,7 +4,10 @@ module.exports = function (kibana) {
|
|||
let { readdirSync } = require('fs');
|
||||
let { resolve, basename } = require('path');
|
||||
|
||||
let modules = {};
|
||||
let modules = {
|
||||
moment$: fromRoot('node_modules/moment/min/moment.min.js')
|
||||
};
|
||||
|
||||
let metaLibs = resolve(__dirname, 'metaLibs');
|
||||
readdirSync(metaLibs).forEach(function (file) {
|
||||
if (file[0] === '.') return;
|
||||
|
@ -17,7 +20,7 @@ module.exports = function (kibana) {
|
|||
uiExports: {
|
||||
modules: modules,
|
||||
noParse: [
|
||||
/node_modules\/(angular|elasticsearch-browser|mocha)\//
|
||||
/node_modules\/(angular|elasticsearch-browser|mocha|moment)\//
|
||||
]
|
||||
}
|
||||
});
|
||||
|
|
|
@ -83,6 +83,7 @@ module.exports = Joi.object({
|
|||
lazyPort: Joi.number().default(5602),
|
||||
lazyHost: Joi.string().hostname().default('0.0.0.0'),
|
||||
sourceMaps: Joi.boolean().default(Joi.ref('$dev')),
|
||||
profile: Joi.boolean().default(false),
|
||||
}).default()
|
||||
|
||||
}).default();
|
||||
|
|
1
webpackstats.json
Normal file
1
webpackstats.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue