Created
October 25, 2017 22:58
Star
You must be signed in to star a gist
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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