Parcel 2: the Automagical Bundler

Rate this content
Bookmark

Parcel 1 was created out of the frustration from configuring slow and hard to configure legacy bundlers like Webpack and in turn started a trend of zero-config tooling. Unfortunately, Parcel 1 had some major design flaws that led to the creation of Parcel 2, a ground-up rewrite of Parcel which aims to resolve those design flaws whilst also creating a bundler that can scale to the size of companies like Atlassian and Adobe and beyond. A new plugin system, bundler targets, optional configuration, stable caches, improved scope-hoisting, improved developer experience and better performance are just a few of the things we’ve been working on for the last 3 years.


In this talk I’ll glance over how Parcel works and talk about a couple of the largest and most exciting new features in Parcel 2.

This talk has been presented at DevOps.js Conf 2021, check out the latest edition of this Tech Conference.

FAQ

Parcel 2 is a comprehensive rewrite of the original Parcel bundler, designed to improve performance, scalability, and configurability. It introduces new features such as a revamped plugin system, enhanced support for different file types through named pipelines, and improved error diagnostics.

Parcel 2 differs from Parcel 1 primarily through its redesigned plugin system, addition of a configuration file, and improvements in performance and error handling. It allows for more granular control over transformations and optimizations specific to file types.

Parcel bundler achieves its speed through the use of caching and multi-threading with workers. It caches every transpilation result from tools like Babel and TypeScript, and parallelizes tasks across all CPU cores to optimize processing time.

Yes, Parcel is designed to be a zero configuration bundler, meaning it works out of the box with sensible defaults for most projects. However, Parcel 2 introduces a config file for advanced scenarios where specific plugin configurations are needed.

Major new features in Parcel 2 include a completely redesigned plugin system, the introduction of named pipelines for handling different file types, improved diagnostics for easier debugging, and a configuration file to specify plugin use per file type. These enhancements significantly improve flexibility and developer experience.

Parcel 2 handles different target environments through the use of targets, which allow developers to build specific bundles for environments like modern browsers or Node.js. This feature supports scenarios like server-side rendering by enabling simultaneous builds for both server and client code.

The new plugin system in Parcel 2 allows for more precise control over the build process, with plugins tailored for specific steps in the pipeline such as transformation or optimization. This modular approach makes it easier to customize and optimize the bundling process for specific project needs.

Jasper De Moor
Jasper De Moor
8 min
01 Jul, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Parcel 2 is a ground-up rewrite of Parcel 1, a fast and scalable zero-configuration web application bundler used by large companies like Atlassian and Adobe. It offers a zero-config approach with good defaults, making it production-ready out of the box. The new features include a revamped plugin system, a configuration file, transformers for file conversion, optimizers for code compression, target support for different browsers, diagnostics for error debugging, and named pipelines for data and JavaScript in different formats. Parcel 2 also supports different import scenarios, such as importing JSON files with named pipelines and using query parameters for image optimization. It includes various performance improvements, stable caches, optimized data structures, enhanced code splitting and bundling, improved scope hosting, and better support for monorepos and libraries. A React example is provided to showcase the simplicity of Parcel and how to use it with React.

1. Introduction to Parcel 2

Short description:

Parcel 2 is a ground-up rewrite of Parcel 1, a fast and scalable zero-configuration web application bundler used by large companies like Atlassian and Adobe.

Hi, everyone. I'm Jasper. I'm a freelance developer and Parcel Core contributor and today I'll talk about Parcel 2. So what is Parcel 2? Parcel 2 is a ground-up rewrite of Parcel 1, but now you might be wondering, what is Parcel 1? Parcel 1 is a fast and scalable zero-configuration web application bundler. This means it's basically like Webpack or Rollup with a big difference in, say, how we actually handle bundling. We try to make it as simple as possible so no configuration We also try to keep it fast and scalable as we're being used in large companies like Atlassian and Adobe.

2. Parcel 2 Features

Short description:

Parcel 2 uses caching and workers to optimize performance. It offers a zero-config approach with good defaults, making it production-ready out of the box. The new features include a revamped plugin system, a configuration file, transformers for file conversion, optimizers for code compression, target support for different browsers, diagnostics for error debugging, and named pipelines for data and JavaScript in different formats.

What makes Parcel fast? Well, we use caching and workers. So we cache every transpolation result from Babel and other transpilers like Typescript, and we also use workers to actually parallelize that work between all your CPU cores. And now you might be wondering, is it really zero config? Well, we actually have a config file, but we try to let you not configure it as much as possible. So we try to have good defaults and our production ready out of the box. So you just create your application. And when you're ready, you can just push it to production and everything will be optimized as it should be.

Parcel 2 has a lot of new features. I'm going to go through a couple of the most large ones and the most interesting ones. So we've revamped our entire plugin system and added a configuration file. So now our plugin system is very different from Parcel 1, as now every step of the pipeline has a different plugin type and interface. So for example, we have transformers which take one type of file and convert it into another type of file. For example, from modern JavaScript to legacy JavaScript, or from TypeScript to JavaScript. We also have, for example, optimizers, which optimize your code or compress it down. For example, we have a Tercer optimizer, which minifies the JavaScript code. We've also added a config file in Porcel 2. The config file isn't actually used to configure anything specific in a transformer or any plugin. It's used to define which plugins should run for a certain file type. As you can see here. For example, this is a TypeScript example where the, for TS and TSX files, the transformer that runs is that TypeScript TSC compiler instead of Babel. And for a validator, we also run a type checker. We've also added targets, which is very useful for things like service site rendering, as you can build a node code and browser code at the same time. But it's also useful, for example, if you still support Internet Explorer without wanting to negatively impact your users that use a modern browser. So you can have two bundles, for example, a modern bundle for Chrome and a legacy bundle for Internet Explorer and other legacy browsers. We've also introduced diagnostics, which is really helpful if you are trying to debug an error and you don't know what's causing it. So, for example, in this screenshot, we imported a file called Babel core instead of the package Babel core. And we suggest the nearest matching packages. For example, in this case, we have a Babel core and a Parcel core. And the one that matches the best is Babel core. That's probably also what you meant. We've also introduced named pipelines which is very useful if you want to have data or JavaScript in different formats.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Levelling up Monorepos with npm Workspaces
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Levelling up Monorepos with npm Workspaces
Top Content
NPM workspaces help manage multiple nested packages within a single top-level package, improving since the release of NPM CLI 7.0. You can easily add dependencies to workspaces and handle duplications. Running scripts and orchestration in a monorepo is made easier with NPM workspaces. The npm pkg command is useful for setting and retrieving keys and values from package.json files. NPM workspaces offer benefits compared to Lerna and future plans include better workspace linking and adding missing features.
Automating All the Code & Testing Things with GitHub Actions
React Advanced Conference 2021React Advanced Conference 2021
19 min
Automating All the Code & Testing Things with GitHub Actions
Top Content
We will learn how to automate code and testing with GitHub Actions, including linting, formatting, testing, and deployments. Automating deployments with scripts and Git hooks can help avoid mistakes. Popular CI-CD frameworks like Jenkins offer powerful orchestration but can be challenging to work with. GitHub Actions are flexible and approachable, allowing for environment setup, testing, deployment, and custom actions. A custom AppleTools Eyes GitHub action simplifies visual testing. Other examples include automating content reminders for sharing old content and tutorials.
Fine-tuning DevOps for People over Perfection
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Fine-tuning DevOps for People over Perfection
Top Content
DevOps is a journey that varies for each company, and remote work makes transformation challenging. Pull requests can be frustrating and slow, but success stories like Mateo Colia's company show the benefits of deploying every day. Challenges with tools and vulnerabilities require careful consideration and prioritization. Investing in documentation and people is important for efficient workflows and team growth. Trust is more important than excessive control when deploying to production.
Why is CI so Damn Slow?
DevOps.js Conf 2022DevOps.js Conf 2022
27 min
Why is CI so Damn Slow?
Slow CI has a negative impact on productivity and finances. Debugging CI workflows and tool slowness is even worse. Dependencies impact CI and waiting for NPM or YARN is frustrating. The ideal CI job involves native programs for static jobs and lightweight environments for dynamic jobs. Improving formatter performance and linting is a priority. Performance optimization and fast tools are essential for CI and developers using slower hardware.
The Core of Turbopack Explained (Live Coding)
JSNation 2023JSNation 2023
29 min
The Core of Turbopack Explained (Live Coding)
Tobias Koppers introduces TurboPack and TurboEngine, addressing the limitations of Webpack. He demonstrates live coding to showcase the optimization of cache validation and build efficiency. The talk covers adding logging and memorization, optimizing execution and tracking dependencies, implementing invalidation and watcher, and storing and deleting invalidators. It also discusses incremental compilation, integration with other monorepo tools, error display, and the possibility of a plugin system for Toolpag. Lastly, the comparison with Bunn's Builder is mentioned.
The Zen of Yarn
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
The Zen of Yarn
Let's talk about React and TypeScript, Yarn's philosophy and long-term relevance, stability and error handling in Yarn, Yarn's behavior and open source sustainability, investing in maintenance and future contributors, contributing to the JavaScript ecosystem, open-source contribution experience, maintaining naming consistency in large projects, version consistency and strictness in Yarn, and Yarn 4 experiments for performance improvement.

Workshops on related topic

Deploying React Native Apps in the Cloud
React Summit 2023React Summit 2023
88 min
Deploying React Native Apps in the Cloud
WorkshopFree
Cecelia Martinez
Cecelia Martinez
Deploying React Native apps manually on a local machine can be complex. The differences between Android and iOS require developers to use specific tools and processes for each platform, including hardware requirements for iOS. Manual deployments also make it difficult to manage signing credentials, environment configurations, track releases, and to collaborate as a team.
Appflow is the cloud mobile DevOps platform built by Ionic. Using a service like Appflow to build React Native apps not only provides access to powerful computing resources, it can simplify the deployment process by providing a centralized environment for managing and distributing your app to multiple platforms. This can save time and resources, enable collaboration, as well as improve the overall reliability and scalability of an app.
In this workshop, you’ll deploy a React Native application for delivery to Android and iOS test devices using Appflow. You’ll also learn the steps for publishing to Google Play and Apple App Stores. No previous experience with deploying native applications is required, and you’ll come away with a deeper understanding of the mobile deployment process and best practices for how to use a cloud mobile DevOps platform to ship quickly at scale.
MERN Stack Application Deployment in Kubernetes
DevOps.js Conf 2022DevOps.js Conf 2022
152 min
MERN Stack Application Deployment in Kubernetes
Workshop
Joel Lord
Joel Lord
Deploying and managing JavaScript applications in Kubernetes can get tricky. Especially when a database also has to be part of the deployment. MongoDB Atlas has made developers' lives much easier, however, how do you take a SaaS product and integrate it with your existing Kubernetes cluster? This is where the MongoDB Atlas Operator comes into play. In this workshop, the attendees will learn about how to create a MERN (MongoDB, Express, React, Node.js) application locally, and how to deploy everything into a Kubernetes cluster with the Atlas Operator.
Azure Static Web Apps (SWA) with Azure DevOps
DevOps.js Conf 2022DevOps.js Conf 2022
13 min
Azure Static Web Apps (SWA) with Azure DevOps
WorkshopFree
Juarez Barbosa Junior
Juarez Barbosa Junior
Azure Static Web Apps were launched earlier in 2021, and out of the box, they could integrate your existing repository and deploy your Static Web App from Azure DevOps. This workshop demonstrates how to publish an Azure Static Web App with Azure DevOps.
How to develop, build, and deploy Node.js microservices with Pulumi and Azure DevOps
DevOps.js Conf 2022DevOps.js Conf 2022
163 min
How to develop, build, and deploy Node.js microservices with Pulumi and Azure DevOps
Workshop
Alex Korzhikov
Andrew Reddikh
2 authors
The workshop gives a practical perspective of key principles needed to develop, build, and maintain a set of microservices in the Node.js stack. It covers specifics of creating isolated TypeScript services using the monorepo approach with lerna and yarn workspaces. The workshop includes an overview and a live exercise to create cloud environment with Pulumi framework and Azure services. The sessions fits the best developers who want to learn and practice build and deploy techniques using Azure stack and Pulumi for Node.js.