Create a gist now

Instantly share code, notes, and snippets.

Embed
You want to serve a browser bundle with Reach, superagent and parse jsx scripts with type="text/jsx"? Install and run `npm run bundle`. You can expose additional content in the window too.
window.React = require('react');
window.ReactDOM = require('react-dom');
window.superagent = require('superagent');
(function() {
'use strict';
const jsx = require('jsx-transform');
const jsxScriptEls = Array.prototype.slice.apply( document.body.querySelectorAll('script[type="text/jsx"]') );
jsxScriptEls.forEach(scriptEl => {
window.superagent(scriptEl.src).end((err, res) => {
if (err || !res.ok) { throw err; }
const code = jsx.fromString(res.text, {factory:'React.createElement', passUnknownTagsToFactory:true, arrayChildren:false});
eval(code);
});
});
})();
{
"scripts": {
"bundle": "browserify bootstrap.js > bundle.js"
},
"devDependencies": {
"browserify": "^14.5.0"
},
"dependencies": {
"jsx-transform": "^2.3.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"superagent": "^3.7.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment