Skip to content

Commit 747790e

Browse files
authored
Merge pull request tompascall#2 from dainyl/master
Added decache to fix caching issues with child dependencies
2 parents cf0e79a + 8a44d73 commit 747790e

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

__tests__/index.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path';
22
const loader = require('../index').default;
3+
jest.mock('decache');
34
const { operator } = require('../index');
45

56
describe('js-to-styles-vars-loader', () => {

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path');
2+
const decache = require('decache');
23

34
const requireReg = /require\s*\(['|"](.+)['|"]\)(?:\.([^;\s]+))?[;\s]/g;
45

@@ -37,7 +38,7 @@ const operator = {
3738
getVarData (modulePath, webpackContext) {
3839
return modulePath.reduce( (accumulator, currentPath) => {
3940
const modulePath = path.join(webpackContext.context, currentPath.path);
40-
delete require.cache[require.resolve(modulePath)];
41+
decache(modulePath);
4142
const moduleData = (currentPath.methodName)? require(modulePath)[currentPath.methodName] : require(modulePath);
4243
webpackContext.addDependency(modulePath);
4344
return Object.assign(accumulator, moduleData);

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@
3131
"babel-preset-es2015": "^6.24.0",
3232
"coveralls": "^2.12.0",
3333
"jest": "^19.0.2"
34+
},
35+
"dependencies": {
36+
"decache": "^4.1.0"
3437
}
3538
}

0 commit comments

Comments
 (0)