Skip to content

Instantly share code, notes, and snippets.

@uetkaje
Last active August 29, 2015 14:10
Show Gist options
  • Save uetkaje/4b7ca7691b72c74079ed to your computer and use it in GitHub Desktop.
Save uetkaje/4b7ca7691b72c74079ed to your computer and use it in GitHub Desktop.
Webpack plugin test 2
var _ = require("lodash");
function testPlugin(options) {
var defaults = {
fileExtensionRegEx: '\.(js|html)$'
};
this.options = _.merge({}, defaults, options || {});
}
testPlugin.prototype.apply = function (compiler) {
var options = this.options;
compiler.plugin('compilation', function (compilation) {
compilation.plugin("module-source-replacement", function (module, content) {
var re = new RegExp(options.fileExtensionRegEx, 'i');
if (!re.test(module.resource)) {
return content;
}
return content.replace('5', '555'); //Modify template function comes here
});
});
};
module.exports = testPlugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment