"Lightning CLI ♥️ Esbuild"

A new experimental bundler

February 4, 2021

The latest release of the Lightning CLI adds support for a new bundler, called esbuild. You can find it here.

Esbuild is an extremely fast bundler and is written in GO. It reduces the time you have to wait for your app to be bundled.

Esbuild is still in an experimental phase, so you need turn it on explicitly by setting the environment var LNG_APP_BUNDLER=esbuild.

For the same reason, not all of the features that are required for an appbundle that runs on the Metrological App Store, have been built in the new bundler. Therefore, you have to make sure to set LNG_APP_BUNDLER=rollup before running the lng upload command.

Possible issues during installation

During the installation of the latest version of the CLI it's possible that you run into an EACCESS permission error. This generally happens if you try to install the CLI running as a superuser (i.e. sudo npm install -g @lightningjs/cli).

The reason behind this error is that Esbuild runs a postinstall script where it switches the user to nobody, and that user obviously doesn't have access permissions to your global node_modules folder (which is owned by the superuser).

The recommended way to fix this issue is to simply not run your NPM commands in sudo mode.

This blog post gives some context on why it's not a good idea in general to install third part (npm) packages with sudo.

Furthermore NPM has some documentation on how to resolve this issue. Or you can follow the instructions in this Stack overflow thread

If for some reason you still need to install the Lightning-CLI in with sudo, you can add an --unsafe-perm=true flag when you install (as described here)

Live Reload

In addition to esbuild, the latest Lightning CLI release provides support for live reload. As a result, it is no longer necessary to refresh your browser after making changes to your source.

You can enable the live reload feature by setting LNG_APP_LIVE_RELOAD=true and optionally LNG_APP_LIVE_RELOAD_PORT=8888 (or any other accepted port value).