Skip to content

Instantly share code, notes, and snippets.

@tmatz
Last active March 16, 2020 03:33
Show Gist options
  • Save tmatz/b8e8eff3fa8d3ce17bc97e73a46b6736 to your computer and use it in GitHub Desktop.
Save tmatz/b8e8eff3fa8d3ce17bc97e73a46b6736 to your computer and use it in GitHub Desktop.
<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