Parcel has a development server built in, which will automatically rebuild your app as you make changes. To start it, run the parcel
CLI pointing to your entry file:
yarn parcel src/index.html
Or when using npm run:
npx parcel src/index.html
Now open http://localhost:1234/ in your browser to see the HTML file you created above.
Next, you can start adding dependencies to your HTML file, such as a JavaScript or CSS file. For example, you could create a styles.css
file and reference it from your index.html
file with a <link>
tag, and an app.js
file referenced with a <script>
tag.
As you make changes, you should see your app automatically update in the browser without even refreshing the page!
In this example, weโve shown how to use vanilla HTML, CSS, and JavaScript, but Parcel also works with many common web frameworks and languages like React and TypeScript out of the box. Check out the Recipes and Languages sections of the docs to learn more.
So far, weโve been running the parcel
CLI directly, but it can be useful to create some scripts in your package.json
file to make this easier. We'll also setup a script to build your app for production using the parcel build
command. Finally, you can also declare your entries in a single place using the source
field so you don't need to duplicate them in each parcel
command.
Now you can run yarn build
to build your project for production and yarn start
to start the development server.
By default Parcel does not perform any code transpilation. This means that if you write your code using modern language features, thatโs what Parcel will output. You can declare your appโs supported browsers using the browserslist
field. When this field is declared, Parcel will transpile your code accordingly to ensure compatibility with your supported browsers.
You can learn more about targets, as well as Parcelโs automatic support for differential bundling on the Targets page.
Now that youโve set up your project, you're ready to learn about some more advanced features of Parcel. Check out the documentation about development and production, and see the Recipes and Languages sections for more in-depth guides using popular web frameworks and tools.