I use JavaScript modules to organize my JS code. I use Rollup.js to package and minify these for distribution to reduce HTTP requests and transfer size, and to provide support for older browsers. So in development I’m using the modules directly and in production I’m using the built files. I was looking for a good way to have some extra code in for development purposes, but removing it for production. This could be used for a lot of things, including testing some code that runs on certain dates for dates other than the current one. I didn’t find a way to do this built in to Rollup, but there is an official plugin called Strip that allows removing specific labelled statements.
Continue reading post "Rollup Strip plugin for dev code"build posts
Playing with GitHub Pages
This past weekend, I started playing with GitHub Pages for the first time. It took a while to figure out, but was somewhat fun. I’ve been interested in it for a while, but was unsure of how to do what I wanted, such as building with PHP, Sass, and Rollup. Turns out it was fairly easy with GitHub Actions to do most any sort of build steps I want. It is very interesting for free static site web-hosting.
Continue reading post "Playing with GitHub Pages"JS: ES Modules and Node bare specifiers via response rewrite
I’ve been playing with JS lately, including ES modules and building with Rollup, Babel, and Terser, along with other accessories. One thing I’m disappointed with of ES modules in the Nodejs ecosystem is dealing with third party imports. Using the “bare” specifiers that Node expects works fine in that environment and thus tools running in it (possibly needing helpers), but they don’t work at all directly in the browser. This is discussed in this post by Jake Archibold, for instance.
Import maps are one solution in the works, but that requires explicitly mapping every dependency, which could get complicated fast when dependencies have dependencies. It also is only in draft stage and only works in Blink based browsers currently.
I eventually gave in to the idea of having server code rewrite the paths in the js file responses to point to a symlinked node_modules folder, similar to what is mentioned in this post by the Polymer project. I created a PHP test server for one of my projects that does this.
First play with ES modules, rollup, webpack
I played with ES modules, rollup, and webpack on my site for the first time over the weekend.
Continue reading post "First play with ES modules, rollup, webpack"