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