Parcel, React & Tailwind to the moon

Parcel, React & Tailwind to the moon

In recent years, thanks to modern technologies, developing web applications is easier than ever. In this article I will show you how to make it even easier by using Parcel, Tailwind, and React.
Parcel…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Matteo Santoro

Parcel, React & Tailwind to the moon

In recent years, thanks to modern technologies, developing web applications is easier than ever. In this article I will show you how to make it even easier by using Parcel, Tailwind, and React.
Parcel is a lightweight and fast bundler for web applications that allows you to manage your project easily and efficiently. Tailwind is a CSS framework used to create clean, modern interfaces, while React, well, it's React and needs no introduction.
Without further ado, let's start creating our webapp!

mkdir my-webapp
npm init -y
npm i -D parcel
npm i react react-dom
mkdir src
touch src/index.html
npm i -D tailwindcss postcss
npx tailwindcss init

Before we dig into the code, we need to edit our package.json as follows

{
  "name": "my-webapp",
  "version": "1.0.0",
  "description": "",
  "scripts": {},
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "parcel": "^2.8.3",
    "postcss": "^8.4.21",
    "process": "^0.11.10",
    "tailwindcss": "^3.2.6"
  },
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  }
}

Inside the root folder create a postcss.config.js file and configure it as follows

module.exports = {
    plugins: [
      require('tailwindcss'),
      require('autoprefixer'),
    ],
};

Create a file called .postcssrc at the same path and paste:

{
  "plugins": {
    "tailwindcss": {}
  }
}

Delete the code inside tailwind.config.js and add

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./src/**/*.{html,js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

In ./src create a file called index.css and fill it up:

@tailwind base;
@tailwind components;
@tailwind utilities;

and fill up ./src/index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="./index.css" rel="stylesheet">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>
    <script type="module" src="./index.js"></script>
</body>
</html>

now create the index.js file where you will start to code using react.

import { createRoot } from 'react-dom/client';
createRoot(app).render(
<div>
  <h1 class="text-3xl font-bold underline">
    Hello world!
  </h1>
</div>
);

To run it locally just run

npx parcel ./src/index.html
or
npm run serve

To build the project

npx parcel build ./src/index.html

⚠️ If you are facing an error regarding relative paths once you build and deploy your code on a webserver, you might need to build as it follows:

parcel build --public-url ./ ./src/index.html

Concluding reflections

Using Parcel, React and Tailwind, it is easy to create a webapp quite efficiently. Using Parcel, you are able to manage your project effectively and quickly, integrating with React and Tailwind to create a worthy webapp.
Don't forget to explore their advanced features to customize your development experience.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Matteo Santoro


Print Share Comment Cite Upload Translate Updates
APA

Matteo Santoro | Sciencx (2023-02-16T20:44:38+00:00) Parcel, React & Tailwind to the moon. Retrieved from https://www.scien.cx/2023/02/16/parcel-react-tailwind-to-the-moon/

MLA
" » Parcel, React & Tailwind to the moon." Matteo Santoro | Sciencx - Thursday February 16, 2023, https://www.scien.cx/2023/02/16/parcel-react-tailwind-to-the-moon/
HARVARD
Matteo Santoro | Sciencx Thursday February 16, 2023 » Parcel, React & Tailwind to the moon., viewed ,<https://www.scien.cx/2023/02/16/parcel-react-tailwind-to-the-moon/>
VANCOUVER
Matteo Santoro | Sciencx - » Parcel, React & Tailwind to the moon. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/16/parcel-react-tailwind-to-the-moon/
CHICAGO
" » Parcel, React & Tailwind to the moon." Matteo Santoro | Sciencx - Accessed . https://www.scien.cx/2023/02/16/parcel-react-tailwind-to-the-moon/
IEEE
" » Parcel, React & Tailwind to the moon." Matteo Santoro | Sciencx [Online]. Available: https://www.scien.cx/2023/02/16/parcel-react-tailwind-to-the-moon/. [Accessed: ]
rf:citation
» Parcel, React & Tailwind to the moon | Matteo Santoro | Sciencx | https://www.scien.cx/2023/02/16/parcel-react-tailwind-to-the-moon/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.