A browserify transform that inlines required values from JSON files
A browserify transform that inlines required values from JSON files.
browserify -t require-key index.js > bundle.js
Say you have a JSON file you want to require from your browserify bundle, but
you only want to include that one value instead of the whole file as a
require-key you can, simply:
var version = require'./package.json'versionvar through = require'./package.json'dependenciesthrough
Then the transform stream will replace those lines with:
var version = "0.0.0"var through = "~2.3.4"
This works for any JSON file, with any value and any set of keys - provided you require the file and access its properties like shown above. If you try and require a malformed file or access undefined values the stream will throw - that's how Node handles the situation too :)
MIT. See LICENSE.md for details.