Skip to content

cacheIdentifier option as a function? #946

Open
@YoonjiJang

Description

@YoonjiJang

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 :/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions