Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
EntryOptionPlugin
to ES2015 class (#3799)
- Loading branch information
1 parent
b710400
commit b5a6684
Showing
1 changed file
with
23 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); | ||
} | ||
} |