UNPKG

kibana-123

Version:

Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic

55 lines (46 loc) 1.92 kB
import FsOptimizer from './fs_optimizer'; module.exports = async (kbnServer, server, config) => { if (!config.get('optimize.enabled')) return; // the lazy optimizer sets up two threads, one is the server listening // on 5601 and the other is a server listening on 5602 that builds the // bundles in a "middleware" style. // // the server listening on 5601 may be restarted a number of times, depending // on the watch setup managed by the cli. It proxies all bundles/* requests to // the other server. The server on 5602 is long running, in order to prevent // complete rebuilds of the optimize content. let lazy = config.get('optimize.lazy'); if (lazy) { return await kbnServer.mixin(require('./lazy/lazy')); } let bundles = kbnServer.bundles; server.exposeStaticDir('/bundles/{path*}', bundles.env.workingDir); await bundles.writeEntryFiles(); // in prod, only bundle when someing is missing or invalid let invalidBundles = config.get('optimize.useBundleCache') ? await bundles.getInvalidBundles() : bundles; // we might not have any work to do if (!invalidBundles.getIds().length) { server.log( ['debug', 'optimize'], `All bundles are cached and ready to go!` ); return; } // only require the FsOptimizer when we need to let optimizer = new FsOptimizer({ env: bundles.env, bundles: bundles, profile: config.get('optimize.profile'), urlBasePath: config.get('server.basePath'), sourceMaps: config.get('optimize.sourceMaps'), unsafeCache: config.get('optimize.unsafeCache'), }); server.log( ['info', 'optimize'], `Optimizing and caching ${bundles.desc()}. This may take a few minutes` ); let start = Date.now(); await optimizer.run(); let seconds = ((Date.now() - start) / 1000).toFixed(2); server.log(['info', 'optimize'], `Optimization of ${bundles.desc()} complete in ${seconds} seconds`); };