From 294c42e574da0f33ec201b0f993bab1e760d6539 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Sun, 7 Apr 2019 15:37:55 -0400 Subject: [PATCH] Scripts: Use cache directory for Babel loader --- packages/scripts/config/webpack.config.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/scripts/config/webpack.config.js b/packages/scripts/config/webpack.config.js index d0d8b9b243b35..6237e09fcbb51 100644 --- a/packages/scripts/config/webpack.config.js +++ b/packages/scripts/config/webpack.config.js @@ -66,12 +66,6 @@ const externals = [ const isProduction = process.env.NODE_ENV === 'production'; const mode = isProduction ? 'production' : 'development'; -const getBabelLoaderOptions = () => hasBabelConfig() ? {} : { - babelrc: false, - configFile: false, - presets: [ require.resolve( '@wordpress/babel-preset-default' ) ], -}; - const config = { mode, entry: { @@ -103,7 +97,20 @@ const config = { 'thread-loader', { loader: require.resolve( 'babel-loader' ), - options: getBabelLoaderOptions(), + options: { + // Babel uses a directory within local node_modules + // by default. Use the environment variable option + // to enable more persistent caching. + cacheDirectory: process.env.BABEL_CACHE_DIRECTORY || true, + + // Provide a fallback configuration if there's not + // one explicitly available in the project. + ...( ! hasBabelConfig() && { + babelrc: false, + configFile: false, + presets: [ require.resolve( '@wordpress/babel-preset-default' ) ], + } ), + }, }, ], },