mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
## Summary ### Asset Optimization in Prod I noticed on a cloud instance that the Webpack-generated JS files were enormous, on the scale of 20+ MB each. Looking into it, and chatting with @spalger, we found that the Webpack [`mode` flag](https://webpack.js.org/concepts/mode/) for production builds was not being set. Before: *91 MB*  After: *29 MB*  ### Webpack Analysis In addition, this PR adds the ability to generate a stats file, usable with the [Webpack Analyzer](http://webpack.github.io/analyse/), to look at how our assets are being built. To run, add an environment flag, e.g: ``` CANVAS_GENERATE_STATS=true node scripts/start ```   ### Checklist Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR. - [x] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) - [ ] ~~Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)~~ - [ ] ~~[Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials~~ - [ ] ~~[Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios~~ - [ ] ~~This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist)~~ ### For maintainers - [ ] ~~This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~~ - [ ] ~~This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~~
This commit is contained in:
parent
0892a4e29f
commit
0385a1ce7c
3 changed files with 18 additions and 5 deletions
5
x-pack/plugins/canvas/.gitignore
vendored
5
x-pack/plugins/canvas/.gitignore
vendored
|
@ -51,4 +51,7 @@ build
|
|||
public/style/index.css
|
||||
|
||||
# Don't commit built plugin files
|
||||
canvas_plugin/*
|
||||
canvas_plugin/*
|
||||
|
||||
# Don't commit the Webpack statistics
|
||||
webpack_stats.json
|
|
@ -4,6 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
const { writeFileSync } = require('fs');
|
||||
const path = require('path');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const {
|
||||
|
@ -13,12 +14,11 @@ const {
|
|||
const sourceDir = path.resolve(__dirname, '../../canvas_plugin_src');
|
||||
const buildDir = path.resolve(__dirname, '../../canvas_plugin');
|
||||
|
||||
export function getWebpackConfig({ devtool, watch } = {}) {
|
||||
export function getWebpackConfig({ devtool, watch, production } = {}) {
|
||||
return {
|
||||
watch,
|
||||
devtool,
|
||||
|
||||
mode: 'none',
|
||||
mode: production ? 'production' : 'none',
|
||||
entry: {
|
||||
'elements/all': path.join(sourceDir, 'elements/register.js'),
|
||||
'renderers/all': path.join(sourceDir, 'renderers/register.js'),
|
||||
|
@ -94,6 +94,16 @@ export function getWebpackConfig({ devtool, watch } = {}) {
|
|||
ignore: '**/__tests__/**',
|
||||
},
|
||||
]),
|
||||
function canvasStatsGenerator() {
|
||||
if (!process.env.CANVAS_GENERATE_STATS) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.hooks.done.tap('canvas_stats', stats => {
|
||||
const content = JSON.stringify(stats.toJson());
|
||||
writeFileSync(path.resolve(__dirname, '../../webpack_stats.json'), content);
|
||||
});
|
||||
},
|
||||
],
|
||||
|
||||
module: {
|
||||
|
|
|
@ -40,6 +40,6 @@ export default function pluginsTasks(gulp, { log, colors }) {
|
|||
});
|
||||
|
||||
gulp.task('canvas:plugins:build-prod', function(done) {
|
||||
del(buildDir).then(() => webpack(getWebpackConfig(), onComplete(done)));
|
||||
del(buildDir).then(() => webpack(getWebpackConfig({ production: true }), onComplete(done)));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue