Skip to content

Commit

Permalink
Refactor EntryOptionPlugin to ES2015 class (#3799)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfranklin authored and TheLarkInn committed Jan 6, 2017
1 parent b710400 commit b5a6684
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions lib/EntryOptionPlugin.js
@@ -1,28 +1,28 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var SingleEntryPlugin = require("./SingleEntryPlugin");
var MultiEntryPlugin = require("./MultiEntryPlugin");
*/
"use strict";

function EntryOptionPlugin() {}
module.exports = EntryOptionPlugin;
const SingleEntryPlugin = require("./SingleEntryPlugin");
const MultiEntryPlugin = require("./MultiEntryPlugin");

EntryOptionPlugin.prototype.apply = function(compiler) {
compiler.plugin("entry-option", function(context, entry) {
function itemToPlugin(item, name) {
if(Array.isArray(item))
return new MultiEntryPlugin(context, item, name);
else
return new SingleEntryPlugin(context, item, name);
}
if(typeof entry === "string" || Array.isArray(entry)) {
compiler.apply(itemToPlugin(entry, "main"));
} else if(typeof entry === "object") {
Object.keys(entry).forEach(function(name) {
compiler.apply(itemToPlugin(entry[name], name));
});
}
return true;
});
};
module.exports = class EntryOptionPlugin {
apply(compiler) {
compiler.plugin("entry-option", (context, entry) => {
function itemToPlugin(item, name) {
if(Array.isArray(item)) {
return new MultiEntryPlugin(context, item, name);
} else {
return new SingleEntryPlugin(context, item, name);
}
}
if(typeof entry === "string" || Array.isArray(entry)) {
compiler.apply(itemToPlugin(entry, "main"));
} else if(typeof entry === "object") {
Object.keys(entry).forEach(name => compiler.apply(itemToPlugin(entry[name], name)));
}
return true;
});
}
}

0 comments on commit b5a6684

Please sign in to comment.