Skip to content

Commit

Permalink
fix: add all babel config files to file dependency (#887)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung authored Apr 3, 2021
1 parent 1669ac0 commit eafd20d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,19 @@ async function loader(source, inputSourceMap, overrides) {
result = await transform(source, options);
}

// TODO: Babel should really provide the full list of config files that
// were used so that this can also handle files loaded with 'extends'.
if (typeof config.babelrc === "string") {
this.addDependency(config.babelrc);
// Availabe since Babel 7.12
// https://github.com/babel/babel/pull/11907
if (config.files) {
config.files.forEach(configFile => this.addDependency(configFile));
} else {
// .babelrc.json
if (typeof config.babelrc === "string") {
this.addDependency(config.babelrc);
}
// babel.config.js
if (config.config) {
this.addDependency(config.config);
}
}

if (result) {
Expand Down

3 comments on commit eafd20d

@alexander-akait
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JLHwung Ideally it should be addBuildDependency, so changing something in configuration(s) invalidate cache of modules (https://github.com/webpack-contrib/postcss-loader/blob/master/src/index.js#L129), we apply the same logic for postcss.config.js and etc config files

@JLHwung
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexander-akait Thanks for the heads up. I couldn't find info about addBuildDependency on webpack.js.org. Is loaderContext.addBuildDependency available on webpack >= 2?

@alexander-akait
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, only for webpack v5, but you use const addBuildDependency = this.addBuildDependency || this.addDependency

Please sign in to comment.