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

Change default cache directory #64

Merged
merged 5 commits into from Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -50,7 +50,7 @@ module.exports = {
| :-------------------: | :----------------------------------------------: | :---------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`cacheContext`** | `{String}` | `undefined` | Allows you to override the default cache context in order to generate the cache relatively to a path. By default it will use absolute paths |
| **`cacheKey`** | `{Function(options, request) -> {String}}` | `undefined` | Allows you to override default cache key generator |
| **`cacheDirectory`** | `{String}` | `path.resolve('./node_modules/.cache/.cache-loader')` | Provide a cache directory where cache items should be stored (used for default read/write implementation) |
| **`cacheDirectory`** | `{String}` | `findCacheDir({ name: 'cache-loader' }) or os.tmpdir()` | Provide a cache directory where cache items should be stored (used for default read/write implementation) |
| **`cacheIdentifier`** | `{String}` | `cache-loader:{version} {process.env.NODE_ENV}` | Provide an invalidation identifier which is used to generate the hashes. You can use it for extra dependencies of loaders (used for default read/write implementation) |
| **`write`** | `{Function(cacheKey, data, callback) -> {void}}` | `undefined` | Allows you to override default write cache data to file (e.g. Redis, memcached) |
| **`read`** | `{Function(cacheKey, callback) -> {void}}` | `undefined` | Allows you to override default read cache data from file |
Expand Down
108 changes: 92 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -38,6 +38,7 @@
"webpack": "^4.0.0"
},
"dependencies": {
"find-cache-dir": "^2.1.0",
"loader-utils": "^1.1.0",
"mkdirp": "^0.5.1",
"neo-async": "^2.6.0",
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Expand Up @@ -2,11 +2,13 @@
import/order
*/
const fs = require('fs');
const os = require('os');
const path = require('path');
const normalizePath = require('normalize-path');
const async = require('neo-async');
const crypto = require('crypto');
const mkdirp = require('mkdirp');
const findCacheDir = require('find-cache-dir');

const { getOptions } = require('loader-utils');
const validateOptions = require('schema-utils');
Expand All @@ -19,7 +21,7 @@ const schema = require('./options.json');

const defaults = {
cacheContext: '',
cacheDirectory: path.resolve('./node_modules/.cache/.cache-loader'),
cacheDirectory: findCacheDir({ name: 'cache-loader' }) || os.tmpdir(),
mistic marked this conversation as resolved.
Show resolved Hide resolved
cacheIdentifier: `cache-loader:${pkg.version} ${env}`,
cacheKey,
read,
Expand Down