Skip to content

Instantly share code, notes, and snippets.

@developit
Created May 12, 2020 19:07
Show Gist options
  • Save developit/2cdcb1e8e979cf41354f2fa17220488b to your computer and use it in GitHub Desktop.
Save developit/2cdcb1e8e979cf41354f2fa17220488b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Preact App with Microbundle</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<div id="preact_root"></div>
<script type="module" src="bundle.js"></script>
</body>
</html>
import { h, render } from 'preact';
import { useReducer } from 'preact/hooks';
function App() {
const [count, increment] = useReducer(c => c + 1, 0);
return (
<div>
{count}
<button onClick={increment}>Increment</button>
</div>
);
}
render(<App />, window.preact_root);
{
"name": "microbundle-preact-example",
"version": "1.0.0",
"source": "index.js",
"scripts": {
"build": "microbundle index.js -f modern -o bundle.js",
"dev": "npm run -s serve & npm run -s build -- --watch",
"serve": "sirv -Dq"
},
"dependencies": {
"preact": "^10.4.1"
},
"devDependencies": {
"microbundle": "^12.0.0",
"sirv-cli": "^0.4.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment