Transformer for browserify to generate clientside code.
###Information
- Include file with
node.js
extention - In this file define exports funtion which return string of client js code
//test.node.js
module.exports = function() {
return "{hello: \"world\"}";
}
- require
test.node.js
file using browserify infrastructure
var test = require("test.node");
test.hello === "world"; // true
npm install browserify-node --save-dev
For example we want to load async text file
//text.node.js
var fs = require("fs");
var md5 = require("md5");
module.exports = function() {
var data = fs.readFileSync("./text.txt");
var hash = md5(data);
var json = "{content:\"" + data + "\"}";
var filename = "test-" + hash + ".json";
fs.writeFileSync(filename, json);
return "function(){ return $.getJSON('" + filename + "'); }"
}
//app.js
var text = require("text.node");
text().done(function(json) {
console.log(json.content);
});