Skip to content

Commit

Permalink
[6.x] [ui/bundles][optimizer] only use caches when in dev mode (#15780)…
Browse files Browse the repository at this point in the history
… (#15854)

* [ui/bundles][optimizer] only use caches when in dev mode

* [optimize/caching] make cache-loader disabling more explicit

* [optimize/caching] clarify why we only want caching in dev
  • Loading branch information
spalger authored Jan 5, 2018
1 parent 56dc541 commit a29c6e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
44 changes: 26 additions & 18 deletions src/optimize/base_optimizer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { resolve } from 'path';
import { writeFile } from 'fs';

import Boom from 'boom';
Expand Down Expand Up @@ -70,8 +69,6 @@ export default class BaseOptimizer {
}

getConfig() {
const cacheDirectory = this.uiBundles.getCachePath();

function getStyleLoaders(preProcessors = [], postProcessors = []) {
return ExtractTextPlugin.extract({
fallback: {
Expand Down Expand Up @@ -101,6 +98,28 @@ export default class BaseOptimizer {
});
}

/**
* 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
* files in optimize/.cache that are not necessary for distributable versions
* of Kibana and just make compressing and extracting it more difficult.
*/
function maybeAddCacheLoader(uiBundles, cacheName, loaders) {
if (!uiBundles.isDevMode()) {
return loaders;
}

return [
{
loader: 'cache-loader',
options: {
cacheDirectory: uiBundles.getCacheDirectory(cacheName)
}
},
...loaders
];
}

const commonConfig = {
node: { fs: 'empty' },
context: fromRoot('.'),
Expand Down Expand Up @@ -136,12 +155,7 @@ export default class BaseOptimizer {
test: /\.less$/,
use: getStyleLoaders(
['less-loader'],
[{
loader: 'cache-loader',
options: {
cacheDirectory: resolve(cacheDirectory, 'less'),
}
}]
maybeAddCacheLoader(this.uiBundles, 'less', [])
),
},
{
Expand All @@ -168,13 +182,7 @@ export default class BaseOptimizer {
{
test: /\.js$/,
exclude: BABEL_EXCLUDE_RE.concat(this.uiBundles.getWebpackNoParseRules()),
use: [
{
loader: 'cache-loader',
options: {
cacheDirectory: resolve(cacheDirectory, 'babel'),
}
},
use: maybeAddCacheLoader(this.uiBundles, 'babel', [
{
loader: 'babel-loader',
options: {
Expand All @@ -183,8 +191,8 @@ export default class BaseOptimizer {
BABEL_PRESET_PATH,
],
},
},
],
}
]),
},
...this.uiBundles.getPostLoaders().map(loader => ({
enforce: 'post',
Expand Down
4 changes: 2 additions & 2 deletions src/ui/ui_bundles/ui_bundles_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export class UiBundlesController {
return resolve(this._workingDir, ...args);
}

getCachePath() {
return this.resolvePath('../.cache', this.hashBundleEntries());
getCacheDirectory(...subPath) {
return this.resolvePath('../.cache', this.hashBundleEntries(), ...subPath);
}

getDescription() {
Expand Down

0 comments on commit a29c6e4

Please sign in to comment.