Last active
March 16, 2020 03:33
-
-
Save tmatz/b8e8eff3fa8d3ce17bc97e73a46b6736 to your computer and use it in GitHub Desktop.
single html react app with require.js (https://gist.githack.com/tmatz/b8e8eff3fa8d3ce17bc97e73a46b6736/raw/single_html_react_with_require.html)
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
<html> | |
<head> | |
<title>Single Html React</title> | |
<script src='https://unpkg.com/requirejs/require.js'></script> | |
</head> | |
<body> | |
<div id='app'></div> | |
<script id='main' type='text/babel'> | |
'strict'; | |
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
const message = 'Hello World!'; | |
ReactDOM.render(<span>{message}</span>, document.getElementById('app')); | |
console.log('script initialized.'); | |
</script> | |
<script id='babel-bootstrap'> | |
const modules = { | |
'babel': 'https://unpkg.com/@babel/standalone/babel.min', | |
'react': 'https://unpkg.com/react/umd/react.production.min', | |
'react-dom': 'https://unpkg.com/react-dom/umd/react-dom.production.min', | |
}; | |
require.config({ paths: modules }); | |
const babel_config = { | |
presets: ['es2015', 'react'], | |
filename: 'embedded', | |
sourceMaps: 'inline' | |
}; | |
require(Object.keys(modules), function(Babel) { | |
const script = Babel.transform( | |
document.getElementById('main').textContent, babel_config); | |
eval(script.code); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment