This gist represents my personal hello-world approach to a simple react-based demo page. It's a bit opinionated in the particular sense that I've come to mistrust a lot of third party tools since I often spend more time debugging them than trying to understand the underlying web technologies. Similarly, sooner or later when you use tools like TypeScript or JSX, there's a moment when you realize you're not actually writing JavaScript. Suddenly you can't paste code into the browser console. You can't send it to another JS environment without rewriting. You can't use that one special tool you need because it has to be fully compatible with the build pipeline which pulls in ten other tools you don't.
That's the basis for my opinions. The result is that I've strived hard to iron out an environment that's as ergonomic as create-react-app with React and JSX, but which avoids the need for any tooling or bundler.
- htm: Like JSX but with JS-native tagged template literals so that you can write ergonomic HTML but keep your JavaScript striclty valid.
- ES Modules: ES modules resolve
import
statements without a bundler! You can finally use browser technologies to write plain HTML projects with proper structure and organization! Very cool! Bundling is still necessary for production in order to minify and deliver optimal code but the time when we need bundling for development is limited! - unpkg.com: A CDN for serving the plain content of NPM modules. It's very reliable. You will need to invoke Mapbox GL or use React as a global, but I think that's a small price to pay for the simplicity. A really nice trick is to add
/browse/
to the root of the URL in order to browse a module's content, e.g. https://unpkg.com/browse/[email protected]/. - st: A super simple static file server. The CLI gets you off the ground, and if you use the API version, you can extend it with arbitrarily complicated things via
http.createServer
, like to generate and serve arbitrary map tiles.
To start the project in this repo, you only need a static file server. (Note that the package.json is only used to install and start the static file server. The code has no local npm-installed dependencies. External libraries are fetched from unpkg.com, though you could copy the files into your local directory if you don't want to load external resources).
Thus you can just install the static file server and load the page:
npm install
npm start
Then open http://localhost:8000/.