I have a CRA project setup and it's working fine. However I'm considering ejecting it and replacing Webpack with Parcel.js. After ejecting, what should I do? Is the index.js
file in the src
folder the only file I need for Parcel?

- 4,054
- 5
- 35
- 75
1 Answers
Your life will be easier if you don't eject (fewer files to delete). You also don't need webpack, Parcel will be your bundler.
If your setup is still close to what CRA gives you out of the box, here's all you have to do:
Uninstall react-scripts:
$ npm rm react-scripts
Install parcel-bundler:
$ npm i -D parcel-bundler
A key difference between CRA and Parcel is that in CRA your entry is always your
src/index.js
andpublic/index.html
is more like a template. In Parcel you can have any .js file as entry, but also any .html file, which is awesome. So move all files frompublic
to thesrc
directory, and you can go ahead and deletepublic
folder since everything now is source. Since your new entry isindex.html
lets make it point to the files correctly.Remove the template variable
%PUBLIC_URL%
in yourindex.html
and point to the files directly. Lets say if you placedindex.html
andfile.ext
both at the root of yoursrc
folder,href="%PUBLIC_URL%/file.ext"
should becomehref="./file.ext"
.CRA injects a
<script />
tag to the end of your html automatically, but in Parcel you need it specified so it knows what to bundle. So add<script src="./index.js" />
to the bottom of your body tag file, right before</body>
(if you put it above your#root
it won't work).Replace your CRA
package.json
tasks with Parcel's:
Change your scripts from
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
to
"scripts": {
"start": "parcel src/index.html",
"prebuild": "rm -rf dist/",
"build": "parcel build src/index.html"
}
Parcel has no eject
and doesn't do test
. Your start
and build
command will both output files to your dist
folder, that's why it is a good idea to delete it before building. Also, add .cache
and /dist
to your .gitignore
.
That's it. Let me know if I missed anything.

- 902
- 8
- 12
-
5I also had to add a .babelrc file with {"presets": ["react-app"]} and install the presets: npm install --save-dev babel-preset-react-app – roeland Aug 19 '18 at 19:48