Skip to content

Commit 356e6e6

Browse files
committed
bug #516 Don't use babel-loader's cacheDirectory for production (Lyrkan)
This PR was merged into the master branch. Discussion ---------- Don't use babel-loader's cacheDirectory for production Currently `cacheDirectory` is always set to `true` in `babel-loader`'s options. This can be an issue because the cache identifier is only based on direct Babel options, but not on external configs such as `.browserslistrc` files or if a `browserslist` key was added to the `package.json` (see babel/babel-loader#690). Disabling that cache entirely in Encore while waiting for a proper solution in `babel` or `babel-loader` would probably not be a good idea, but we could mitigate the problem by disabling it only for the prod environment. Closes #514 Commits ------- ae74298 Don't use babel-loader's cacheDirectory for production
2 parents 0facc4d + ae74298 commit 356e6e6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/loaders/babel.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ module.exports = {
2020
getLoaders(webpackConfig) {
2121
let babelConfig = {
2222
// improves performance by caching babel compiles
23-
// we add this option ALWAYS
23+
// this option is always added but is set to FALSE in
24+
// production to avoid cache invalidation issues caused
25+
// by some Babel presets/plugins (for instance the ones
26+
// that use browserslist)
2427
// https://github.com/babel/babel-loader#options
25-
cacheDirectory: true
28+
cacheDirectory: !webpackConfig.isProduction()
2629
};
2730

2831
// configure babel (unless the user is specifying .babelrc)

test/loaders/babel.js

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ describe('loaders/babel', () => {
4949
});
5050
});
5151

52+
it('getLoaders() for production', () => {
53+
const config = createConfig();
54+
config.runtimeConfig.babelRcFileExists = true;
55+
config.runtimeConfig.environment = 'production';
56+
57+
const actualLoaders = babelLoader.getLoaders(config);
58+
// cacheDirectory is disabled in production mode
59+
expect(actualLoaders[0].options).to.deep.equal({
60+
cacheDirectory: false
61+
});
62+
});
63+
5264
it('getLoaders() with react', () => {
5365
const config = createConfig();
5466
config.enableReactPreset();

0 commit comments

Comments
 (0)