Minimal React project template
Although it is strongly criticised for its bloat, create-react-app is often a go to when starting a new React project. I like to start things from the bottom up, adding things up as I need them so, I prefer a minimalistic approach.
It’s actually very easy to setup a bare-bones React project using parcel. Here’s how to do it.
Initialise npm project
mkdir react-minimal
cd react-minimal
npm init -y
mkdir src
Some adjustments are needed to package.json
. I’m gonna change the main
to
source
, pointing to the index.html
of my project. I’m gonna create an
empty src/index.html
for the interim.
touch src/index.html
Here’s the resulting package.json.
|
|
Add parcel
I’m using parcel
as build system and bundler.
npm install --save-dev parcel
Add React
Obviously, I’m adding React as dependency
npm install react react-dom
Sample application
I’m gonna start with the App
component:
|
|
I’m using it in index.jsx
which is my entry point.
|
|
This is included in index.html
.
|
|
This can be rendered with parcel
.
|
|
Or bundled using the build
command
|
|
That’s it!
Babel and JSX translation
You don’t need Babel at all as parcel is taking care of JSX translation out of the box.
Example code
Code discussed in this post is available in gitlab repo.