Overview:
The Parcel React Boilerplate is a simple React boilerplate that uses Parcel bundler, linter, prettier, and other tools to create new React apps quickly. This guide focuses on creating a smaller and simpler boilerplate than the Create React App (CRA) version with Parcel. It is recommended for people who are new to React and want to understand the problems that CRA solves before using it. Parcel is a fast bundler that does not require a config file and provides features like tree shaking, caching, code splitting, and live reload out of the box.
Features:
- No need for a config file with Parcel bundler.
- Fast build and rebuild times with caching.
- Tree shaking out of the box with multicore processing.
- Code splitting and live reload are available by default.
Installation:
- Create a new folder and initialize the project with
yarn init -y(or any package manager of your choice). - Create a
.babelrcfile in the project root folder and add the following content:
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
- Add a start script and a build script in the
package.jsonfile:
"scripts": {
"start": "parcel src/index.html",
"build": "parcel build src/index.html"
}
- Change
src/index.htmlto the route of your main HTML file. - Set up the folder structure as mentioned in the guide.
- In the
index.htmlfile, import theindex.jsfile and add a<div>element with the idrootwhere the React content will be added. - In the
index.jsfile, add the basic React code. - Install additional extras by running the following commands:
- To install PropTypes for prop validation, run
yarn add -D prop-types. - To install autoprefixer for CSS autoprefixing, run
yarn add -D autoprefixer postcss. - Create a
.postcssrcfile in the project root folder and add the following content:
{
"plugins": {
"autoprefixer": {}
}
}
- Create an
index.scssfile and import it in theindex.jsfile.
Summary:
The Parcel React Boilerplate provides a simplified and lightweight setup for creating React apps using Parcel bundler. It focuses on offering the essential features needed for React development without the additional complexity of tools like Create React App. The guide explains the installation process and highlights the benefits of using Parcel, such as its fast build times, tree shaking, code splitting, and live reload capabilities. Additional extras like prop validation with PropTypes and CSS autoprefixing with autoprefixer can be easily added for convenience during development.