Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from CRA to Vite #2

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

Migrate from CRA to Vite #2

wants to merge 12 commits into from

Conversation

bgins
Copy link
Member

@bgins bgins commented Aug 12, 2021

This PR shows how to convert the CRA version of this app to use Vite.

Here are the steps needed to make the switch:

Install vite and update scripts

Install vite and @vitejs/plugin-react-refresh as dev dependencies and remove react-scripts

npm install vite @vitejs/plugin-react-refresh --save-dev
npm remove react-scripts

Update npm scripts in package.json to use vite instead of react-scripts.

After removing react-scripts, this should look like

  "scripts": {
    "start": "vite",
    "build": "vite build",
    "serve": "vite preview"
  },

Rename Files

Rename all files with React components from .js to .jsx.

Move index.html and reference the entry point

Move index.html to the root of the project and add

<script type="module" src="./src/index.jsx"></script>

right before </body> towards the end of the file.

Remove %PUBLIC_URL%

Remove all %PUBLIC_URL% in index.html. For example

<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />

should be changed to

<link rel="apple-touch-icon" href="/logo192.png" />

Add Vite config

Add a vite.config.ts. Make sure to set build.target to es2020.

Update build directory

Update .gitignore to ignore /dist instead of /build.

Update build in fission.yaml from ./build to ./dist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant