Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Install Node.js if you haven't already
- Create a folder
- Use
- npm init
- ...to create a project, filling in the answers to the questions it asks.
- Install vite, react, and react-dom:
- npm install vite react react-dom
- Create an index.html file (below).
- Create an index.jsx file with your React code (below).
- Modify package.json so the "scripts" section is:
- "scripts": {
- "dev": "vite dev",
- "build": "vite build"
- },
- Then run your code in dev mode:
- npm run dev
- or build a production package:
- npm run build
- index.html:
- <!doctype html>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=Edge">
- <title>Example</title>
- </head>
- <body>
- <div id="root"></div>
- <script type="module" src="./index.jsx"></script>
- </body>
- </html>
- index.jsx:
- import React from "react";
- import { createRoot } from "react-dom/client";
- class App extends React.Component {
- constructor(props) {
- super(props);
- }
- render() {
- return (
- <div>
- <h1>Hello World</h1>
- </div>
- );
- }
- }
- createRoot(document.getElementById("root")).render(<App />);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement