Migrating Snowpack to Vite (and Docker!)

About eighteen months ago I migrated a small Javascript app to use Snowpack development tooling. (This was mostly for fun, I had already had it working with Webpack.) Snowpack claimed simple dev tooling with nearly instant updates, using the power of ES Modules. It worked pretty well.

About six months ago, the team that developed Snowpack realized that their efforts had paralleled those of the Vite.js tooling. Vite.js also used ES Modules, and provides a mature code base and strong community support. Since the Snowpack team wanted to work on other projects (Astro), they switched their underlying tooling to use Vite.js.

So… I decided to see what it would take to migrate my Snowpack project to use Vite.js. Everything I had read said that it was easy. Here’s a field report from what was required.

A Side Project – Using Docker: Since this Javascript app was a side project, I have also been using it as a learning environment. I had read Jonathan Bergknoff’s Run More Stuff in Docker that made a lot of sense to me. (The magic of using Docker is that once you’ve created the instance, all the tool and dependency versions remain the same. It’s easy then to hand the Dockerfile to a colleague who can build an identical development environment in a few minutes. It also avoids cluttering my daily-driver laptop with multiple versions of Node, npm, Go, Python, rust, and any number of little-used tooling – they’re all encapsulated in the Docker container.)

So I decided to investigate whether using Docker to create the Javascript tooling would make my life better. Googling around led to Andrew Welch’s vitejs-docker-dev project. It builds a Docker instance with full development tooling (Vite.js, pnpm, hot reloading, etc.) that watches the source files in your local directory for updates. You develop the code using your favorite editing tools. Changes are immediately reflected in your browser/test environment. This is very slick. The vitejs-docker-dev repo has good documentation. It describes a lot of background of how the Docker machine gets built and how to use it.

Update: Andrew Welch (who created the vitejs-docker-dev project) sent me a link to his article about using “Docker for all the things.” It’s a good adjunct to the original “Run More Stuff in Docker” post.

Back to the main story – here are the steps I followed to get my Snowpack project on the air with Vite.js:

  1. Create the Docker instance. Clone the vitejs-docker-dev repo. Then run make docker to put the set of development tools into a new Docker instance. This one-time step takes a few minutes. You may see several warnings (as described in a Github issue) but these don’t seem to be important.
  2. Check the default Vite.js app builds on Docker. Run make vite-pnpm run dev in one terminal window, then run make app-pnpm run dev in a second window (waiting between the commands as described in the README). Click the http://localhost:3000 URL to see if the test Vite app starts up. Edit the index.html file to see if the change is reflected in the web browser. (It should be…)
  3. Customize the /app directory for your app. Copy all your app’s files into the app directory. (I renamed the original to app-old and created a new app directory.) This required a bit of jiggering to adjust between Snowpack and Vite.js, such as:
    • My index.html file for Snowpack was in the public directory; for Vite.js, I moved it to the top-level app directory
    • Copy the package.json and other important directories to app directory
    • Adjust the paths for index.html: Snowpack bundles source files from /src into the /dist directory; Vite.js processes the files directly from /src
    • I can’t remember whether I made other tweaks; it certainly wasn’t odious.
  4. Remove references to the Snowpack modules from the package.json file. Optionally, you could take the opportunity to update the versions of dependencies.
  5. Rebuild the Docker instance (#1 above) and restart the development process (#2 above). Click the link to http://localhost:3000 and your app should begin to run. You’ll probably need to make adjustments, but you’ll be substantially on the air.

TL;DR The process of converting to Vite.js wasn’t very hard (at least, not on my small project). It required a little farbling around, but nothing terrible. The jury’s still out on whether vitejs-docker-dev will make my life better – but I think it just might.

Using Apple’s RPM tool

macOS Monterey ships with a tool that measures the responsiveness of your network connection. It saturates the network with traffic for 20 seconds, then measures the rate of short transactions to compute “Responses Per Minute.” Big numbers (above 2000) mean your network remains responsive when the network is heavily loaded. Small numbers (under 800 or so) mean your network isn’t responsive – potentially caused by bufferbloat.

There’s an iOS version described at https://support.apple.com/en-gb/HT212313

Stuart Cheshire and Vidhi Goel talked about the RPM tool at WWDC 2021. Apple also published an Internet-Draft that describes the RPM technique

Here’s a sample run from my Mac. The RPM tool displays my download and upload speeds (nominally 25mbps), and the number of simultaneous flows required to saturate the link (12, in this case). It shows the responsiveness as 1995 round-trips per minute. That’s really good: the average latency – even during heavy load – only increases a bit above the baseline (idle) 21 msec.

% /usr/bin/networkQuality -v
==== SUMMARY ====
Upload capacity: 22.657 Mbps
Download capacity: 23.755 Mbps
Upload flows: 12
Download flows: 12
Responsiveness: High (1995 RPM)
Base RTT: 21
Start: 11/7/21, 7:18:37 AM
End: 11/7/21, 7:18:47 AM
OS Version: Version 12.1 (Build 21C5021h)
%

Here’s a video that shows the tool in operation: https://youtu.be/e9DUTB9okMA

NameD•Tective — mDNS over AppleTalk

[From the Archives of Amusing Technology…] Back in the ’90s, Dave Fisher and I created NameD•tective, a Macintosh control panel that gave any Mac on the Dartmouth network a static DNS name.

It used Name Binding Protocol to let someone create a DNS name based on their name plus their AppleTalk zone. The DNS name had the form: person-name.AppleTalk-zone…dartmouth.edu. The NameD•tective server looked up the NBP name, and returned the computer’s current IP address.

This screen shot shows an example: cd-changer.kiewit.atzone.dartmouth.edu was a server in my office that distributed information to other developers in the Kieiwt building. NameD•tective probably didn’t get broad use at Dartmouth, but it was a neat demonstration project. It led Dave and me to develop the MacDNS software that was shipped as part of Apple’s Internet Connection Kit. Here’s the page from Dartmouth’s website archived by the Wayback Machine: https://web.archive.org/web/19961220043011/http://www.dartmouth.edu/pages/softdev/named.html

Today, computer naming is much simpler. Modern operating systems let a computer specify a mDNS (multicast DNS) name that can be directly looked up to find a host that provides the service.

Comcast modems decrease bufferbloat

Last month, Comcast released a paper Improving Latency with Active Queue Management (AQM) During COVID-19 that shows that their PIE AQM dramatically decreases lag/latency (by a factor of 10X — from 250 msec down to 15-30 msec.) From the paper (page 13):

 

… As explained earlier, for two variants of XB6 cable modem gateway, upstream DOCSIS-PIE AQM was enabled on the CGM4140COM (experiment) variant but was not available on the TG3482G (control) variant during the measurement period

At a high level, when a device had AQM it consistently experienced between 15-30 milliseconds of latency under load. … [The] non-AQM devices experienced in many cases 250 milliseconds or higher latency under load.

See if you can get an XB6 / CGM4140COM cable modem

Astonishing Lidar View of NH

The NH Stone Wall Mapper project uses Lidar data to display small variations in ground elevation. A UNH project built this map to identify stone walls in the state.

This site can be “misused” (in a good way) to show lots of other topographic features. Here’s a “Lidar view” of the grounds of Loch Lyme Lodge, near Post Pond. The features are shaded as if the sun were shining from the northeast. (Update: 31 Dec: Thanks to the good folks at the NH Geological Survey, the link now goes directly to the desired view!)

But wait… there’s more! You can turn on and off various “layers” to see other kinds of information. To do this:

  1. At the top-left, click the Layers Icon to display various layers
  2. Check on or off the Hillshade box to “show or hide the trees”…
  3. Click the More… icon to enable other features, such as the “Swipe Layers” that lets you compare two layers…

So much fun – play around!. Turn on/off layers, scroll to other parts of NH. If you find something interesting, send me a note and I’ll post it. Enjoy!

Transmission of Covid-19

A friend (thanks, Ted!) directed me to a nice science-based article that assigns some probabilities of risks of transmitting a disease like coronavirus. The author highlights two major scenarios:

  1. Warm body transmission: how far apart should you be from other people if you want to avoid transmission from another “warm body”
  2. Surface-based transmission: what precautions should you take when you go somewhere that others have passed through recently.

You won’t be surprised by the takeaways:

  • 6 foot distancing is good
  • wearing a mask is good
  • washing hands is good

…but some of the discussion and details are interesting. View the full article at Medium.

Get a better microphone…

Now that we’re computer conferencing all the time, I needed a better microphone, (My MacBook Pro’s built-in microphone doesn’t work well. The volume is too low – perhaps there’s something wrong.) I suspect many others would benefit from a better microphone, too. Not only do they give a better sound, but a microphone close to the mouth minimizes other nearby sounds.

So I went on a quest to find a better solution. I found a variety of options, and tested several. I put my notes here so I can remember:

  • Bluetooth earpieces Any Bluetooth headset/earpiece that is advertised to work with your cellphone will probably work. They’re lightweight, have decent microphones, and boast a certain amount of noise cancellation. (Look for ones that can be paired to two devices, so you can use it with both your computer and your cell phone.) I own the Plantronics M70 – it works fine, and has 11-hour talk time (and when I don’t use it, the charge lasts for weeks). Apple AirPods or knock-offs should also work well, although I have not tested them.
  • Earbuds with cables Apple EarPods (corded) ($15 with shipping from MacSales) or from Amazon work fine for videoconferencing.
  • External microphone if you want to include multiple people on your end, or if you don’t want to be “cabled” to the computer… I own the Amazonbasics Desktop Microphone because it was highly-rated in a Wirecutter article. It works great.
  • USB Audio In Since not all computers have a combined headphone and microphone jack, you can add a USB “sound card” to virtually any computer. I checked out the TROND External USB AudioAdapter Sound Card and it works fine with all the 1/8 inch (3.5mm) audio inputs.
  • Gaming headsets These large (and heavy) headphones have a microphone on a stalk to pick up your voice. I own one, and it works just fine. But it’s obtrusive (viewers see those “cans” on my head) and not terribly comfortable. There are a zillion options: you can Google “gaming headset” to see the range.
  • My favorite For years, I used a Plantronics headset with my cordless phone. It’s lightweight, has good sound, and it’s cheap ($20). But it has a 2.5mm plug – so I bought an adapter cable ($8). This plugs right into the headphone jack of my MacBook Pro (both headphone and microphone work perfectly). But if this doesn’t work on your computer, get the TROND adapter.

All this assumes your computer has either USB, Bluetooth, or 1/8 inch/3.5mm headphone inputs. (All modern computers do.) I’ve included links to Amazon, but most items are available from lots of places.

Let me know what you’re using for your videoconferencing pleasure – richb.lyme@gmail.com. Thanks!

Enable Virtual Public Meetings

Change.org is hosting a petition calling on Governor Chris Sununu of NH to allow for “virtual meetings” for the normal business of towns and municipalities. I would include Select Boards as well as those listed below. As I said on the petition page:

It will be months before we are “back to normal”. Most town boards or committees might be able to “skip a meeting” because of an emergency. But real residents have real needs, and cannot realistically wait for boards that have been shut down for a protracted period of time.

Specifically, the petition requests the Governor to:

  • Allow and encourage for both state and local municipal boards to continue with standard timelines and regularly scheduled board hearings through a virtual meeting template, such as Zoom. This includes, but is not limited to, historic district commissions, conservation commissions, planning and zoning boards.
  • Allow and encourage board members, city staff, design professionals and the public to participate through an open video forum and email regardless of city or town charter.
  • Provide state guidelines on how the local municipalities should conduct meetings and insist that mandated timelines for board decisions be maintained.

If you agree, please go to the petition at: https://www.change.org/p/new-hampshire-governor-chris-sununu-enable-virtual-public-meetings-for-planning-and-zoning-boards-in-nh and pass the word to your friends. Thanks.


Feel free to share this post on Facebook, LinkedIn, Twitter, or email by clicking one of the icons below. Any opinions expressed here are solely my own, and not those of any public bodies, such as the Lyme Planning Board or the Lyme Community Development Committee, where I am/have been a member. I would be very interested to hear your thoughts – you can reach me at richb.lyme@gmail.com.

Renewable Sources of Energy article on the Warrant

I am pleased to present my first “guest posting” here on the blog. I support this article, and I hope you can cast your vote on the ballot at Town Meeting, March 10, 7am to 7pm.

Jim Nourse has been working over the last six months to gather support for an article on the Warrant in March to encourage the Town of Lyme to use 100% renewable sources of energy by 2030. Here’s his open letter to the Town, with the text of the Article 22 appended:

As we look forward to Town Meeting, I wanted to give you an update on where the effort to put forward a warrant article moving the Town and its residents away from fossil fuels and towards clean, renewable energy stands. The Energy Committed has voted 7-0 to support this article; the Select Board voted 3-0 to support the article. I have attached the article below.

I will be speaking in favor of the article at Little Town Meeting on Tuesday, March 3, 7 pm. I would love some support, if appropriate, from members of the audience. I would also encourage you to talk about the article with your neighbors and friends. It would send a very clear message if the votes at Town Meeting were overwhelmingly positive. A few talking points:

  1. This article is a non-binding advisory article to give a “sense of the Town” in moving in the direction of a non-fossil fuel energy future. As such it does not mandate any actions by either town officials or residents. It is assumed that town officials and residents will continue to be fiscally prudent as we make this transition.
  2. The Energy Committee sees this as the start of a town-wide conversation about how Lyme makes a transition to a non-fossil fuel, sustainable future.
  3. The article discusses the major reasons that this transition is both necessary and immediate. Fossil fuels are finite in supply and even as advances in technology make it possible to extract the remaining supplies (think fracking as an example), the cost of that extraction will continue to become more expensive. And, perhaps the most important reason, the need to solve rapidly intensifying climate change which in large part is driven by our burning of fossil fuels.
  4. People will ask what this transition might look like. If, as we expect, most voters support this article, it will give the Select Board and town committees a clear sense that this is the direction the town wishes to go in. It might mean a review and reshaping of energy guidelines for new municipal construction. It might mean the amending of zoning regulations to make it more conducive for community solar projects. It will guide the town’s committees as they update the Town Master Plan. It will most likely mean more community-wide initiatives like Weatherize and Solarize Lyme. It may lead to increased collaboration with area towns to aggregate electricity purchases in an attempt to both secure the most economical rate as well as purchasing from renewable sources of electricity. It may mean seeking state and federal grants for renewable energy projects. It will mean making sure that those residents who cannot afford to move to renewable energies are included in projects that provide access to those energies that are affordable.
  5. A final point for me is the recognition that this transition will not be easy or straightforward. There will probably be times when the town or residents choose a “better” alternative, but not the “best” alternative given financial or logistical limitations. People may wonder how we will ever arrive at 100% renewable electricity by 2030, or for heating and transportation by 2050. My response is that these are goals, that the sooner we begin to work towards them, the farther along we will be. If by 2030, only 65% of our electricity comes from clean, renewable sources then that’s still more than it is today.

And speaking of beginning right away – there are two town projects on the immediate horizon that should be influenced by a goal of transitioning away from fossil fuels and towards renewable energy. You will most likely hear about these at both town meetings. The pellet boilers that serve the town garage are in need of replacement and there are plans to construct a new fire station. There are choices in what type of heating source to install as well as design choices for the new fire station that will impact whether it can be easily retrofitted to renewables, i.e. PV panels, in the future. I hope that you will add your voices in calling for those in charge of making these decisions to move away from fossil fuels and towards a future of renewable energy.

Many thanks for your support of this transition. Let me know if you have any questions or suggestions.

Best,
Jim

Article 22-Renewable Sources of Energy

(Can’t read the PDF above? Download it at
https://RandomNeuronsFiring.com/wp-content/uploads/2020/02/Warrant-Article-22-Final-02.20.2020.pdf
)

Public Meetings, February 22 & 25

There will be two public meetings at the Converse Library in Lyme to discuss the petitioned Planned Development amendment. Not only does it provide a measure of fairness for landowners near commercial properties on Route 10 but it enables new housing opportunities here in Lyme.

I support this Planned Development amendment. We all know that Lyme (and the entire Upper Valley) have a housing problem. Seniors can’t downsize in Lyme, many people who work here can’t afford to live here, and there’s no economical way to build modest price housing.

We are looking for a lively but civil conversation on this important topic. Please attend and let your friends know about the meetings. Thank you.

Saturday, February 22, 11am, Converse Library
Tuesday, February 25, 7pm, Converse Library