webpack/lib/ProvidePlugin.js

18 lines
603 B
JavaScript
Raw Normal View History

2013-02-11 03:37:30 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var ModuleParserHelpers = require("./ModuleParserHelpers");
function ProvidePlugin(definitions) {
this.definitions = definitions;
2013-02-11 03:37:30 +08:00
}
module.exports = ProvidePlugin;
ProvidePlugin.prototype.apply = function(compiler) {
Object.keys(this.definitions).forEach(function(name) {
var request = this.definitions[name];
compiler.parser.plugin("expression " + name, function(expr) {
return ModuleParserHelpers.addParsedVariable(this, name, "require(" + JSON.stringify(request) + ")");
});
}, this);
2013-02-11 03:37:30 +08:00
};