Execute ES Modules on the CLI

Jonathan Neal shared this little snippet on Twitter: Execute JavaScript modules like: bash ./command.js 1. Add the funky header.2. Optional: Omit the extension to not write `.js`.3. Optional: `chmod +x command` to not write `bash `.https://t.co/rhlPg2XPRJ pic.twitter.com/nbAvTFtt0w — Jonathan Neal (@jon_neal) July 25, 2021 Here’s the code: “:” //#;exec /usr/bin/env node –input-type=module – “$@” < …

Control the behavior of JavaScript imports with Import Maps

Shipping in Chrome 89 are Import Maps, which allows control over what URLs get fetched when importing modules. Let’s take a look at this very welcome addition. When importing ES Modules (on the web), you need to refer to them using their full filenames or URLs: import moment from “/js/moment/moment.js”; import { partition } from …

The several ways to import React

With the release of React 17 we also had to change the way we import React: To clarify: ✅ import { useState } from 'react'✅ import * as React from 'react'🟡 import React from 'react' The third one is called "default import" and in the long term (maybe in 19 or 20) we will stop …

Skypack — Load optimized npm packages with no install and no build tools

I was delighted to read that CodePen now has built-in support for Skypack. This is a huge step forward to working with packages on CodePen. Great addition to the product! But what exactly is Skypack? Well, it’s the successor to the aforementioned Pika CDN with some extra juice: Skypack not only serves packages that export …

Worth It: Modern JS edition

“Worth It: Modern JS edition” is a small tool to analyze how much less JavaScript is downloaded in modern browsers as a result of it using the module/nomodule pattern. Worth It: Modern JS edition → 💡 The module/nomodule pattern is a technique to ship ES2015 modules to browsers that support, whilst also keeping older browsers …

jQuery, now using ECMAScript module syntax

A nice commit migrating away from AMD Modules to ECMAScript modules recently landed in the jQuery repo. Once published as a new release, you’ll be able to actually import $ using the modern ES module syntax: import $ from "jquery"; $('#message').text('Hi from jQuery!'); Handy if you’re modernizing a legacy project that still uses jQuery. 💡 …

Pika CDN – A CDN for modern JavaScript

Yesterday the aforementioned Pika announced some new things. One of the things that stood out is Pika CDN: The Pika CDN was built to serve the 60,000+ npm packages written in ES Module (ESM) syntax. This module syntax runs natively in the browser, so you can build for the web without a bundler. With our …

create-es-react-app – A create-react-app like template using only es-modules (no build step).

create-es-react-app is a create-react-app like template demonstrating how far you can get creating progressive web apps (using react) with no build step. It takes advantage of static and dynamic imports which enables you to break up your app into small reusable ES modules that are compiled for you by the browser at run time. TIL: …