Exploring the best way to embed a widget in a webpage
In a previous job, I created a number of visualisation widgets, that were supposed to be dropped into a webpage and render themselves. Back then, I used RequireJS to load the widgets' dependencies. RequireJS was not the right technology and I was never satisfied with the result.
This is the way to go.
The only file that needs to be embedded into the webpage is dist/widget.js
.
<script src="widget.js"></script>
A sample page can be found in dist/index.html
.
The widget should work out of the box in the browser.
- preact
- ES2015
- webpack
- fetch polyfill (whatwg-fetch)
npm install
npm run watch
open dist/index.html in browser