Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Hard to set custom cacheIdentifier that uses cache-loader version number #30

Open
jochakovsky opened this issue Jan 27, 2018 · 3 comments

Comments

@jochakovsky
Copy link

jochakovsky commented Jan 27, 2018

The default value for cacheIdentifier is cache-loader:{version} {process.env.NODE_ENV}. My project has multiple webpack config files where the step that uses cache-loader gets the same input from previous loaders but performs different transformations (eg. Istanbul instrumentation for test builds only).

I like that the default string includes the cache-loader version number, since it makes sense to invalidate the cache when this loader is updated. When setting a custom value, it is difficult to replicate this behavior since retrieving the cache-loader version number is tricky. It seems like the best options are hard-coding the version number into the string and hoping to remember to update it when upgrading to a new version of cache-loader, or some hacky manipulation of the path returned by require.resolve("cache-loader").

Couple of possible fixes:

  1. Append the user-provided cacheIdentifier to the default string instead of replacing the default string
  2. Export the cache-loader version number

Happy to submit a PR with whatever fix is deemed best!

@filmic
Copy link

filmic commented Mar 23, 2018

You can read the version number from package.json file:

const fs = require('fs-extra');
const version = fs.readJsonSync('node_modules/cache-loader/package.json').version;

(alternatively use async method fs.readJson to get a Promise)

@Cleecanth
Copy link

I believe you can just use:

const version = require('cache-loader/package.json').version;

@prograhammer
Copy link

What exactly does the cacheIdentifier do? The documentation isn't clear.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants