Skip to content

Commit

Permalink
Add support for the latest Webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
larixer committed Jul 25, 2017
1 parent 4696b3c commit 81ec55b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Expand Up @@ -3,7 +3,8 @@
"eslint:recommended"
],
"env": {
"node": true
"node": true,
"es6": true
},
"rules": {
}
Expand Down
16 changes: 12 additions & 4 deletions index.js
Expand Up @@ -57,6 +57,14 @@ VirtualModulesPlugin.prototype.writeModule = function(filePath, contents) {
}
};

function setData(storage, key, value) {
if (storage.data instanceof Map) {
storage.data.set(key, value);
} else {
storage.data[key] = value;
}
}

VirtualModulesPlugin.prototype.apply = function(compiler) {
var self = this;

Expand All @@ -71,17 +79,17 @@ VirtualModulesPlugin.prototype.apply = function(compiler) {
if (this._virtualFiles) {
Object.keys(this._virtualFiles).forEach(function(file) {
var data = this._virtualFiles[file];
this._statStorage.data[file] = [null, data.stats];
this._readFileStorage.data[file] = [null, data.contents];
setData(this._statStorage, file, [null, data.stats]);
setData(this._readFileStorage, file, [null, data.contents]);
}.bind(this));
}
};

compiler.inputFileSystem._writeVirtualFile = function(file, stats, contents) {
this._virtualFiles = this._virtualFiles || {};
this._virtualFiles[file] = {stats: stats, contents: contents};
this._statStorage.data[file] = [null, stats];
this._readFileStorage.data[file] = [null, contents];
setData(this._statStorage, file, [null, stats]);
setData(this._readFileStorage, file, [null, contents]);
};
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,12 +1,12 @@
{
"name": "webpack-virtual-modules",
"version": "0.1.6",
"version": "0.1.7",
"description": "Webpack Virtual Modules",
"main": "index.js",
"scripts": {
"lint": "eslint --fix .",
"posttest": "npm run lint",
"test": "NODE_ENV=coverage nyc --check-coverage --lines 100 --branches 100 npm run tests",
"test": "NODE_ENV=coverage nyc --check-coverage --lines 95 --branches 95 npm run tests",
"tests": "mocha",
"tests:watch": "mocha -w"
},
Expand Down

0 comments on commit 81ec55b

Please sign in to comment.