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");
|
|
|
|
|
2013-12-18 06:21:49 +08:00
|
|
|
function ProvidePlugin(definitions) {
|
|
|
|
this.definitions = definitions;
|
2013-02-11 03:37:30 +08:00
|
|
|
}
|
|
|
|
module.exports = ProvidePlugin;
|
|
|
|
ProvidePlugin.prototype.apply = function(compiler) {
|
2013-12-18 06:21:49 +08:00
|
|
|
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
|
|
|
};
|