Last active
August 29, 2015 14:10
-
-
Save uetkaje/4b7ca7691b72c74079ed to your computer and use it in GitHub Desktop.
Webpack plugin test 2
This file contains hidden or 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
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