A browserify transform that inlines required values from JSON files
Want to see pretty graphs? Log in now!
npm install require-key
|2||downloads in the last week|
|4||downloads in the last month|
|Last Published By|
|Version||0.0.0 last updated 6 months ago|
|Dependencies (6)||map-async, through, browser-resolve, esprima, astw, escodegen|
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').version var through = require('./package.json').dependencies.through
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.