-
Notifications
You must be signed in to change notification settings - Fork 4
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
[DT-295] Migrate from Create React App to Vite #2779
Conversation
d07534e
to
ff01968
Compare
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [ | ||
react({ include: /\.(mdx|js|jsx|ts|tsx)$/ }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The include
is required to also support mdx
files
], | ||
assetsInclude: ['**/*.md'], | ||
build: { | ||
outDir: 'build', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required to generate builds in the same location
assetsInclude: ['**/*.md'], | ||
build: { | ||
outDir: 'build', | ||
target: 'es2022' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required to avoid an error with top-level await
s
target: 'es2022' | ||
}, | ||
server: { | ||
port: 3000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required to keep compatibility with CRA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I suggest that we add a host and https block to server?
host: 'local.dsde-dev.broadinstitute.org',
https: {
key: fs.readFileSync(`./server.key`),
cert: fs.readFileSync(`./server.crt`),
},
This also needs a new import
import fs from 'fs';
This starts up similarly to how we're running the app now:
VITE v6.1.0 ready in 106 ms
➜ Network: https://local.dsde-dev.broadinstitute.org:3000/
➜ press h + enter to show help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like key
and cert
can directly take file paths, so the fs
import is not required.
import {BrowserRouter} from 'react-router-dom'; | ||
|
||
const load = async () => { | ||
unregister(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functionality is deprecated.
@@ -91,5 +92,6 @@ | |||
], | |||
"engines": { | |||
"node": ">=22.11.0" | |||
} | |||
}, | |||
"type": "module" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-module builds of Vite are deprecated.
@@ -41,10 +41,9 @@ | |||
}, | |||
"scripts": { | |||
"analyze": "npm run build; source-map-explorer build/static/js/main.*", | |||
"start": "react-scripts start", | |||
"genschemas": "./scripts/compile-jsonschema.sh", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The genschemas
script no longer exists.
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
<script type="module" src="./src/index.tsx"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only functional change to this file is adding this line.
1f405d4
to
040664f
Compare
@@ -15,7 +15,9 @@ COPY types /usr/src/app/types | |||
COPY public /usr/src/app/public | |||
COPY package.json /usr/src/app/package.json | |||
COPY package-lock.json /usr/src/app/package-lock.json | |||
COPY index.html /usr/src/app/index.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file moved location, and therefore needs to be included in the build.
COPY tsconfig.json /usr/src/app/tsconfig.json | ||
COPY vite.config.js /usr/src/app/vite.config.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new file that needs to be included in the build.
040664f
to
32a7b69
Compare
"start": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the new vite
commands.
@@ -81,6 +81,7 @@ | |||
"source-map-explorer": "2.5.3", | |||
"typescript": "4.9.5", | |||
"typescript-eslint": "7.17.0", | |||
"vite": "6.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the latest versions of the react
plugin and vite
.
9a1414c
to
3e888d3
Compare
@@ -13,8 +13,8 @@ module.exports = defineConfig({ | |||
component: { | |||
specPattern: ['**/*.spec.js', '**/*.spec.jsx', '**/*.spec.ts', '**/*.spec.tsx'], | |||
devServer: { | |||
framework: 'create-react-app', | |||
bundler: 'webpack', | |||
framework: 'react', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new Vite config for Cypress.
@@ -2,7 +2,7 @@ | |||
<browserconfig> | |||
<msapplication> | |||
<tile> | |||
<square150x150logo src="%PUBLIC_URL%/images/favicon/mstile-150x150.png"/> | |||
<square150x150logo src="/images/favicon/mstile-150x150.png"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%PUBLIC_URL%
is a CRA-specific path.
src/registerServiceWorker.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functionality is deprecated.
src/components/SpinnerComponent.jsx
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are actually JSX files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work 👍🏽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job!
Addresses
https://broadworkbench.atlassian.net/browse/DT-295
Summary
Migrates from Create React App to Vite. Requires #2780 to go in first.
Have you read Terra's Contributing Guide lately? If not, do that first.