Browserify transform to make source code replacements using grasp.
$ npm install --save-dev graspify
Define replacements in package.json:
{
"main": "./index.js",
"graspify": [
["equery", "__ + __", "{{.l}} - {{.r}}"],
["squery", "#myVar", "myVariable"]
],
"dependencies": {
"graspify": "^0.0.1"
}
}
Run graspify transform:
$ browserify -t graspify index.js
Sometimes it is handy to perform global transform, to affect nested modules:
$ browserify -g graspify index.js
.
Graspify can be used programmatically:
b.transform(graspify, replacements);
Pass replacements
as a second optional argument. It will be merged with the ones defined in package.json
.
var browserify = require('browserify');
var b = browserify('./entry.js');
var graspify = require('graspify');
b.transform(graspify, [
["squery", "#myVar", "myVariable"],
["equery", "__ + __", "{{.r}} + {{.l}}"],
//you can also pass a replacement funtion
["equery", "require($module)", function(){
return "require('stub')"
}]
])