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.

8 min
01 Jul, 2021

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.

Available in Español

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.

3. Parcel 2 Import and Optimization

Short description:

Parcel 2 supports different import scenarios, such as importing JSON files with named pipelines and using query parameters for image optimization. The new version also includes various performance improvements, stable caches, optimized data structures, enhanced code splitting and bundling, improved scope hosting, and better support for monorepos and libraries. To demonstrate the simplicity of Parcel, a React example is provided, showcasing how to add Parcel and React, configure scripts in package.json, and run development and production builds with ease.

For example, we have JSON imports here. So, in one case, you might want a URL of the JSON file. In another case, you might want the text of the JSON file. So, the actual content. And you can use that with named pipelines. For example, URL colon data JSON will return a URL to the JSON file, and text, data, JSON will return the contents of that JSON file. We can also use query parameters, for example, for optimizing images in this case. I've taken an example from our image optimizer, which is URL colon for URL import, and then parcel.JPG is a parcel logo image. And then, you have query parameters. The format is WebP, and the quality is 70%. That's a pretty heavily compressed image.

We've also done a lot more changes than just these few that I've highlighted. We've improved performance more than 2x. We've made our caches stable, so you no longer have to remove the cache now and then. You can leave it there. We've also improved our data structures to use way less memory. This also helped us scale to the size of, for example, Atlassian. We've also improved code splitting and bundling. For example, we have an HTTP2 strategy now, which allows you to have more code splitting than before. We've also made scope hosting stable, so now you can safely use it in production. We've also improved our monorepo and library support. For example, targets can be used to compile an entire monorepo with a single command.

So to show that Parcel is actually really simple, I'm going to go through a little React example. So you first add Parcel and React and React DOM for this example. And then in the package.json, you have two scripts. Devscript, which just starts the index.html entry point, using Parcel. And then the build command, which runs Parcel build and index.html and creates an optimized bundle. So index.html contains a diff with an app ID and a script which references the index file. Index.tsx just contains a simple hello world application. And then if we run Yarn dev, it simply works without any configuration. And Yarn build creates a production ready bundle without any configuration.

This was my talk about Parcel. Thank you for listening.

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

React Advanced Conference 2021React Advanced Conference 2021
19 min
Automating All the Code & Testing Things with GitHub Actions
Top Content
Code tasks like linting and testing are critical pieces of a developer’s workflow that help keep us sane like preventing syntax or style issues and hardening our core business logic. We’ll talk about how we can use GitHub Actions to automate these tasks and help keep our projects running smoothly.
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Fine-tuning DevOps for People over Perfection
Demand for DevOps has increased in recent years as more organizations adopt cloud native technologies. Complexity has also increased and a "zero to hero" mentality leaves many people chasing perfection and FOMO. This session focusses instead on why maybe we shouldn't adopt a technology practice and how sometimes teams can achieve the same results prioritizing people over ops automation & controls. Let's look at amounts of and fine-tuning everything as code, pull requests, DevSecOps, Monitoring and more to prioritize developer well-being over optimization perfection. It can be a valid decision to deploy less and sleep better. And finally we'll examine how manual practice and discipline can be the key to superb products and experiences.
DevOps.js Conf 2022DevOps.js Conf 2022
27 min
Why is CI so Damn Slow?
We've all asked ourselves this while waiting an eternity for our CI job to finish. Slow CI not only wrecks developer productivity breaking our focus, it costs money in cloud computing fees, and wastes enormous amounts of electricity. Let’s take a dive into why this is the case and how we can solve it with better, faster tools.
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
The Zen of Yarn
In the past years Yarn took a spot as one of the most common tools used to develop JavaScript projects, in no small part thanks to an opinionated set of guiding principles. But what are they? How do they apply to Yarn in practice? And just as important: how do they benefit you and your projects?
In this talk we won't dive into benchmarks or feature sets: instead, you'll learn how we approach Yarn’s development, how we explore new paths, how we keep our codebase healthy, and generally why we think Yarn will remain firmly set in our ecosystem for the years to come.

Workshops on related topic

DevOps.js Conf 2022DevOps.js Conf 2022
152 min
MERN Stack Application Deployment in Kubernetes
Workshop
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.
React Summit 2023React Summit 2023
88 min
Deploying React Native Apps in the Cloud
WorkshopFree
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.
DevOps.js Conf 2022DevOps.js Conf 2022
13 min
Azure Static Web Apps (SWA) with Azure DevOps
WorkshopFree
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.
DevOps.js Conf 2022DevOps.js Conf 2022
163 min
How to develop, build, and deploy Node.js microservices with Pulumi and Azure DevOps
Workshop
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.