Last active
August 29, 2015 14:10
-
-
Save uetkaje/2952153fe3f2adce7fda to your computer and use it in GitHub Desktop.
Webpack plugin test
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
var _ = require("lodash"); | |
var fs = require("fs"); | |
var OriginalSource = require('webpack-core/lib/OriginalSource'); | |
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("succeed-module", function (module) { | |
var re = new RegExp(options.fileExtensionRegEx, 'i'); | |
if (re.test(module.resource)) { | |
var fileContent = fs.readFileSync(module.resource, { encoding: 'utf8' }); | |
fileContent = fileContent.replace('5', '555'); //Modify template function comes here | |
module._source = new OriginalSource(fileContent, module.identifier()); | |
} | |
}); | |
}); | |
}; | |
module.exports = testPlugin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/home/emre/Projects/sf/node_modules/webpack/node_modules/webpack-core/node_modules/source-map/lib/source-map/source-node.js:177
throw new TypeError(
^
TypeError: Expected a SourceNode, string, or an array of SourceNodes and strings. Got /*