Skip to content

Instantly share code, notes, and snippets.

@uetkaje
Last active August 29, 2015 14:10
Show Gist options
  • Save uetkaje/2952153fe3f2adce7fda to your computer and use it in GitHub Desktop.
Save uetkaje/2952153fe3f2adce7fda to your computer and use it in GitHub Desktop.
Webpack plugin test
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;
@uetkaje
Copy link
Author

uetkaje commented Dec 6, 2014

/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 /*

at SourceNode_add [as add] (/home/emre/Projects/sf/node_modules/webpack/node_modules/webpack-core/node_modules/source-map/lib/source-map/source-node.js:177:13)
at SourceNode.<anonymous> (/home/emre/Projects/sf/node_modules/webpack/node_modules/webpack-core/node_modules/source-map/lib/source-map/source-node.js:168:14)
at Array.forEach (native)
at SourceNode_add [as add] (/home/emre/Projects/sf/node_modules/webpack/node_modules/webpack-core/node_modules/source-map/lib/source-map/source-node.js:167:14)
at new SourceNode (/home/emre/Projects/sf/node_modules/webpack/node_modules/webpack-core/node_modules/source-map/lib/source-map/source-node.js:41:31)
at Source.ReplaceSource._splitSourceNode (/home/emre/Projects/sf/node_modules/webpack/node_modules/webpack-core/lib/ReplaceSource.js:72:20)
at Source.<anonymous> (/home/emre/Projects/sf/node_modules/webpack/node_modules/webpack-core/lib/ReplaceSource.js:33:24)
at Array.forEach (native)
at Source.ReplaceSource._bake (/home/emre/Projects/sf/node_modules/webpack/node_modules/webpack-core/lib/ReplaceSource.js:31:20)
at SourceMapNodeSource.node (/home/emre/Projects/sf/node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js:42:36)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment