Blog

Home / Blog

How to transform JavaScript development using popular tools

Billy Yann
Deep learning and machine learning specialist, well-versed with experience in Cloud infrastructure, Block-chain technologies and Big Data solutions.
June 7, 2021


JavaScript is one of the most prominent unique web technologies. As the JavaScript skills evolve, the websites will enter a different dimension of power and creativity. JavaScript itself is fairly compact, yet very flexible.

An exotic era of bundlers and build tools is challenging the inertia of “good enough” tools. Exceptional speed, a reasonable development experience, and higher-quality production builds are all core areas of the new breed. ESM, esbuild, Parcel, pnpm, Rollup, Snowpack, and Vite are the new stars rendering JS advancement easier.

JavaScript

ECMAScript modules (ESM)

ECMAScript modules are the authorized standard format to package JavaScript code for reuse. Modules are interpreted using a variety of import and export statements. It can be thought of as a ‘reusable unit of JavaScript’ that the browser examines and dynamically links at runtime. As such, it’s not a technical tool, but it has wide implications for JS development and tools. There is a lot of chaos and uncertainty for a while in the use of the JavaScript module (with Node.js landing on CommonJS syntax). But with the current approval of ESM and its extensive implementation in browsers, new possibilities are opening up.

The common form of ESM syntax is seen in Itemizing 1. The fundamental line is the syntax for importing a default export. The next make use of destructuring to stipulate members contained in the module.

Itemizing 1. ESM syntax

ESM is Javascript's suggestion to implement a standard module system. Even Microsoft Edge now aids ESM, so all leading browsers presently support it.

The browser employs modules in two ways: either in the JavaScript scripts it encompasses, or directly in the “module” script tag, illustrated in Itemizing 2.

Itemizing 2. Importing through script module

In Itemizing 2, the initial two script tags indicate how to target an absolute URL. At first, the src attribute is being used, and in the second, to run the JavaScript import. The third script tag expresses a relative import broadcast from the same domain.

When a script from another domain is inserted, CORS restrictions apply.

For several years, many bundlers (most commonly Webpack nowadays) have been employed to bundle scripts to bypass browser limitations with add-ons. Extensive browser help for ESM changes and the next generation of tools has been improved to take advantage of this support.

Still, that bundling has a part to play, as allowing the browser to naively request all of an app’s add-ons would derive from the poor performance of a multitude of requests. Bundling, minification, smart code sharing / CSS, etc. are however vital for good performance.

esbuild

esbuild is a CLI, NPM package, and Go module that creates bundling JavaScript accessible and fast. esbuild is a reasonably new entry in the bundler field. It is inscribed in Go as opposed to JavaScript, has speed and benefits from the built-in parallelism of Go. It also depends on the intelligent use of shared memory during analysis and code generation.

To get an idea about the speed of esbuild, checking is the means. The benchmarks reflect performance increases of 100 times and more related to other bundlers.

By default esbuild bundles for the browser but it is also able to bundle for Node.js. It acts the same as other build tools by connecting to NPM through package.json and node_modules. It also proposes a JavaScript API that can be used to bundle build commands if the needs become too complicated and heavy for command line use. Itemizing 3 shows a representation of using this API.

esbuild concentrates on bundling and does not involve a server in development mode. Many facets, like code / CSS split, are still in progress.

Esbuild had ~ 25K GitHub stars and ~ 570K weekly downloads from NPM as of May 2021. This makes esbuild the smallest of the projects depicted here, but its usage is rising quickly and its performance promises make it a tempting option.

Itemizing 3. Using the esbuild JavaScript API

esbuild develops a fully self-contained bundle that integrates the application code and all dependencies. A lot plug-ins are accessible to handle a variety of use cases, from Svelte to PostCSS to YAML. Out of the box, esbuild favors popular varieties such as TypeScript, JSX, and JSON.

Parcel

Parcel is a web application bundler, distinguished by its developer experience. It is a tool identical in spirit to Webpack and Rollup. In addition to lowering setup costs, Parcel claims to boost performance, although it cannot match esbuild’s claims in this regard.

Package comprises No Configuration Code Splitting and Hot Module Replacement (HMR) out of the box. It also incorporates many file types (like images) by default, and it can regulate them without additional configuration.

Parcel has around 38,000 stars on GitHub and around 64,000 weekly downloads from NPM (weekly downloads occur to be leveling off). These stats make it a reasonable mid-size option.

pnpm

pnpm is an npm-compatible package manager for JavaScript that proposes considerable developments in both speed and disk space usage. It is not a bundler or a build tool. Rather, it is an instant replacement for the NPM dependency tool. This brings it related to Wire for the goal, but pnpm takes a different approach: it uses hard links to flatten the node_modules tree, thus simplifying dependency management and avoiding duplicate dependencies.

In addition to saving disk space, this structure opens up some performance advancements, as seen in these benchmarks, which implies that pnpm outperforms other package managers in most tasks. pnpm also involves pnpx, a tool similar to npx, for running packages.

pnpm has ~ 11K GitHub stars and ~ 191K weekly downloads from NPM. This is the default package manager for SvelteKit and is detecting strong improvement in its use. pnpm seems to be an excellent candidate for the next de facto standard dependency manager.

Rollup

Rollup is a module bundler for JavaScript which compiles small pieces of code into something enormous and more complicated, such as a library or application. Rollup is a bundler that enables to use ESM syntax everywhere. It softens the numerous syntaxes seen in the wild (CJS, AMD, UMD, EMS, etc.) and bundles the code into a syntax that just works. Additionally, Rollup proposes a “tree shake,” which is the ability to assess the codebase and eliminate unused imports. This has evident performance benefits.

Like esbuild and other bundlers, Rollup is related to package.json and node_modules through NPM.

To forget about the module syntax while using Rollup, just use ESM. In common, Rollup attempts to give the experience of future JS development, where everything is currently unified on ESM.

Rollup is quite comparable to Webpack in operation, but unlike Webpack, it supports Node.js output. In addition, some creators report a simpler and smoother experience with Rollup.

Rollup does not assist hot module replacement by default.

Rollup has a strong community and a plug-in ecosystem. As of May 2021, it had ~ 20K GitHub stars and ~ 4.8 million weekly downloads from NPM.

Vite

Quickly was initially a build tool specifically for Vue, but now aids general use. It evolved the authorized build solution for SvelteKit it is the same for increasingly wide use. Vite concentrates on managing two regulations for JS development: running the development mode and building for production. Vite is not a bundler and rather entrusts the production consolidation tasks to Rollup.

Formulated to be prompt, Vite boasts its fast-start development server and hot module replacement. Experience backs up Vite’s claims – these features work quite rapidly compared to something like Webpack.

Vite’s speed developments are based on exploiting ESM and using esbuild for pre-grouping. Using ESM suggests that Vite can offload grouping work to the browser during improvement and earn more granularity when determining which files will be served during edits.

Vite presently uses Rollup for production builds (to get features like CSS splitting) but may upgrade to esbuild in the future.

Vite’s development experience is its powerful selling point – its hot-swap module is really fast. It presently has ~ 27K GitHub stars and ~ 124K weekly NPM downloads, with a sharp improvement in downloads seen over the past two months.

Snowpack

Snowpack is a lightning-fast frontend build tool, developed for the new web. It is an alternative to heavier, more complicated bundlers like webpack or Parcel in the development workflow. Snowpack is another speed-driven bundler and growth server. It gives fast server startup, ESM support with smart caching, fast hot-swapping of modules, and low-configuration aid for several file types. Snowpack is identical in spirit to Rollup and Parcel.

Snowpack helps targeted hot module replacement for JavaScript, CSS, and CSS modules out of the box. It similarly has a powerful community of plug-ins.

Snowpack has ~ 18K GitHub stars and ~ 55K weekly downloads from NPM.

Wrap Up - The future of JS tools

Most of the modern browsers support JavaScript and it is also favored in mobile devices. Webpack has been an incredible de facto standard, but it’s starting to show its age. The modern tools, with the new landscape in mind, are sure to provide better performance and an exceptional developer experience in the future.

It has a large community behind it that ensures its popularity well into the future. JavaScript stays a thrilling and rapidly evolving world to develop in.