`cacheIdentifier` option as a function?
- Dominant language
- JavaScript
- Stars
- 4.8k
- Forks
- 456
- Avg merge
- 9h 19m
- Merged PRs (30d)
- 2
Description
## **BEFORE YOU SUBMIT** please read the following:
**I'm submitting a feature request**
**Webpack Version:**
5.x
**Babel Core Version**:
7.18.x
**Babel Loader Version**:
8.2.x
**Please tell us about your environment:**
OSX 13.x
**Current behavior:**
`cacheIdentifier` is an option that defaults to stringified json with `@babel/core` version, `babel-loader` version, and "`options`" object.
https://github.com/babel/babel-loader/blob/v8.2.5/src/index.js#L189-L193
**Expected/desired behavior:**
Want to be able to set it to a function whose argument includes values used in the default value.
```
// webpack.config.js
{
loader: 'babel-loader',
options: {
cacheIdentifier({ options, babelCoreVersion, babelLoaderVersion }) {
// returns string
return JSON.stringify({ options, babelCoreVersion, babelLoaderVersion, someOtherKey: 'cache-busting value' });
},
},
},
```
Maybe something like this could work.
```
// babel-loader/src/index.js
const cacheIdentifierOptions = {
options,
"@babel/core": transform.version,
"@babel/loader": version,
};
let {
// ...
cacheIdentifier = JSON.stringify(cacheIdentifierOptions),
// ...
} = loaderOptions;
if (cacheIdentifier === 'function') {
cacheIdentifier = cacheIdentifier(cacheIdentifierOptions);
}
```
* **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with a gist/jsbin of your webpack configuration.**
* **What is the expected behavior?**
* **What is the motivation / use case for changing the behavior?**
The default value makes sense for most use cases and includes info that depends on the file being transpiled, such as filename, but I can't access it :/
Contributor guide
Research direction
Start in src/index.js around lines 189-193, where the default cacheIdentifier is assembled from the Babel and loader versions and options. Confirm how loader options are read, then make the requested behavior complete when cacheIdentifier is a function receiving those default-value inputs while retaining the existing default behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, webpack
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100