The source field within any target declared in package.json can specify one or more entry files that are specific to that target. For example, you could build your frontend and backend simultaneously, or your desktop and mobile apps. See below for details about configuring targets.
Now we can just npm run start to develop and npm run build to build.
Parcel supports Hot reloading. As you make changes to your code, Parcel automatically rebuilds the changed files and updates your app in the browser
CORS policy
If you access dist/index.html and get CORS policy error
access to script at 'file:///index.e59da450.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
It is because we use ES6 module for script. ES6 modules are subject to same-origin policy, we can't run it locally without served from a server.
In this tutorial we will be creating a React app with Parcel 2 with Typescript and Tailwind
Install the following dependencies. Parcel supports TypeScript out of the box without any additional configuration.
We will be adding files to
src
folderCreate a
.postcssrc
with the followingSupposed we are adding files in
src
folder, allow Tailwind to act in the following content paths intailwind.config.js
In our
index.html
, add a placeholderdiv
to inject later with scriptHere is how we inject our React component
Our
App
component can be simple like thisSpecify Tailwind layers in
App.css
We will be adding 2 handy scripts to our
package.json
, specifyingsrc/index.html
as our starting pointRead more about source
Now we can just
npm run start
to develop andnpm run build
to build.Parcel supports Hot reloading. As you make changes to your code, Parcel automatically rebuilds the changed files and updates your app in the browser
CORS policy
If you access
dist/index.html
and get CORS policy errorIt is because we use
ES6 module
for script. ES6 modules are subject to same-origin policy, we can't run it locally without served from a server.Take a look at Web Extension
Read more