@@ -4,6 +4,9 @@ const path = require('path');
4
4
const mkdirp = require ( 'mkdirp' ) ;
5
5
const async = require ( 'async' ) ;
6
6
const loaderUtils = require ( 'loader-utils' ) ;
7
+ const pkg = require ( '../package.json' ) ;
8
+
9
+ const defaultCacheDirectory = path . resolve ( '.cache-loader' ) ;
7
10
8
11
function loader ( ...args ) {
9
12
const callback = this . async ( ) ;
@@ -58,13 +61,21 @@ function loader(...args) {
58
61
}
59
62
60
63
function pitch ( remainingRequest , prevRequest , dataInput ) {
61
- const options = loaderUtils . getOptions ( this ) || { } ;
62
- const cacheDirectory = options . cacheDirectory || path . resolve ( '.cache-loader' ) ;
64
+ const loaderOptions = loaderUtils . getOptions ( this ) || { } ;
65
+ const defaultOptions = {
66
+ cacheDirectory : defaultCacheDirectory ,
67
+ cacheIdentifier : JSON . stringify ( {
68
+ 'cache-loader' : pkg . version ,
69
+ env : process . env . NODE_ENV || 'development' ,
70
+ } ) ,
71
+ } ;
72
+ const options = Object . assign ( { } , defaultOptions , loaderOptions ) ;
73
+ const { cacheIdentifier, cacheDirectory } = options ;
63
74
const data = dataInput ;
64
- data . remainingRequest = remainingRequest ;
65
75
const callback = this . async ( ) ;
66
- const hash = digest ( remainingRequest ) ;
76
+ const hash = digest ( remainingRequest + cacheIdentifier ) ;
67
77
const cacheFile = path . join ( cacheDirectory , `${ hash } .json` ) ;
78
+ data . remainingRequest = remainingRequest ;
68
79
data . cacheFile = cacheFile ;
69
80
fs . readFile ( cacheFile , 'utf-8' , ( readFileErr , content ) => {
70
81
if ( readFileErr ) {
0 commit comments