Created
May 5, 2016 14:34
-
-
Save MattSurabian/dd3d013f786f2ff8c6c7a64e0824cf69 to your computer and use it in GitHub Desktop.
easy to generate webpack module with custom object body
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
'use strict'; | |
var NormalModule = require('webpack/lib/NormalModule'); | |
function JsonModule(request, parser, body) { | |
NormalModule.call(this, request.request, request.request, request.request, [], request.request, parser); | |
this.body = body; | |
return this; | |
} | |
JsonModule.prototype = Object.create(NormalModule.prototype); | |
JsonModule.prototype.build = function(options, compilation, resolver, fs, callback) { | |
var _this = this; | |
NormalModule.prototype.build.call(this, options, compilation, resolver, { | |
readFile: function(filepath, callback) { | |
var buffy = new Buffer(`module.exports = { ${_this.body} };`); | |
callback(null, buffy); | |
} | |
}, callback); | |
}; | |
JsonModule.prototype.constructor = JsonModule; | |
module.exports = JsonModule; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment