i'm trying bundle library .js
file loadable script tag. want have library available under variable in browser console (in other words, want export window
object). how can in browserify?
this existing grunt-browserify config:
browserify: { options: { watch: "on", banner: "<%= banner %>", browserifyoptions: { insertglobalvars: "on", nobuiltins: true, detectglobals: false } }, dist: { files: { 'dist/json-schema-faker.js': ['lib/index.js'] } }
currently can't use bundled library outside package.
i know browserify supports external requires, instead of
var jsf = require('json-schema-faker'); jsf.dosomething();
i prefer do:
jsf.dosomething();
directly (so assigning jsf
window
automatic). how that, possibilities of browserify in matter?
in browserified code, have access normal window
variable, , it's aliased global
compatibility node. can add end of code:
global.jsf = jsf;
if you'd rather not have json-schema-faker
export itself, wrap in module re-exports jsf
, attaches global
.
Comments
Post a Comment