javascript - Making compiled typescript code globally accessible -
i've been working on little project recently, , ran issue of having project me accessible in rest of page.
here's deal:
it's javascript router. doing sake of interest. i've set typescript compiler via grunt , module loading , concatenation via grunt-requirejs.
here's grunt file: https://github.com/forestdev/jsroute/blob/master/gruntfile.js
the output, however, doesn't seem generate export window. have been googling how export code window or anywhere other javascript files access it.
could problem wrapper? need insert custom wrapper of this? what's general rule of thumb of making typescript project global?
edit:
forgot list index file: https://github.com/forestdev/jsroute/blob/master/src/index.ts
ignore line new instance of object. want export object else create new instance of themselves.
found way handle exposing global scope.
within grunt build requirejs script added custom wrapper, is:
wrap: { start: '(function(global) {', end: 'global.jsroute = global.jsroute || require("index").router; }(window));' }
this seems fix issue had of exporting script global scope. correctly loads script on window load well, other scripts have access right away.
hope makes sense. correct way of doing well.
Comments
Post a Comment