@@ -26,6 +26,7 @@ const { getBrowsersList } = require(`./browserslist`)
2626
2727const customOptionsCache = new Map ( )
2828const configCache = new Map ( )
29+ const babelrcFileToCacheKey = new Map ( )
2930
3031module . exports = babelLoader . custom ( babel => {
3132 return {
@@ -71,6 +72,18 @@ module.exports = babelLoader.custom(babel => {
7172 partialConfig . files . forEach ( configFilePath => {
7273 configCacheKey += `_${ configFilePath } `
7374 } )
75+
76+ // after generating configCacheKey add link between babelrc files and cache keys that rely on it
77+ // so we can invalidate memoized configs when used babelrc file changes
78+ partialConfig . files . forEach ( configFilePath => {
79+ let cacheKeysToInvalidate = babelrcFileToCacheKey . get ( configFilePath )
80+ if ( ! cacheKeysToInvalidate ) {
81+ cacheKeysToInvalidate = new Set ( )
82+ babelrcFileToCacheKey . set ( configFilePath , cacheKeysToInvalidate )
83+ }
84+
85+ cacheKeysToInvalidate . add ( configCacheKey )
86+ } )
7487 }
7588
7689 let { options } = partialConfig
@@ -138,3 +151,22 @@ module.exports = babelLoader.custom(babel => {
138151 } ,
139152 }
140153} )
154+
155+ module . exports . BabelConfigItemsCacheInvalidatorPlugin = class BabelConfigItemsCacheInvalidatorPlugin {
156+ constructor ( ) {
157+ this . name = `BabelConfigItemsCacheInvalidatorPlugin`
158+ }
159+
160+ apply ( compiler ) {
161+ compiler . hooks . invalid . tap ( this . name , function ( file ) {
162+ const cacheKeysToInvalidate = babelrcFileToCacheKey . get ( file )
163+
164+ if ( cacheKeysToInvalidate ) {
165+ for ( const cacheKey of cacheKeysToInvalidate ) {
166+ configCache . delete ( cacheKey )
167+ }
168+ babelrcFileToCacheKey . delete ( file )
169+ }
170+ } )
171+ }
172+ }
0 commit comments