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

Move to vite from react-app-rewired for example project development build #2411

Closed
KonstantinEpam23 opened this issue Mar 24, 2023 · 3 comments · Fixed by #2487
Closed

Move to vite from react-app-rewired for example project development build #2411

KonstantinEpam23 opened this issue Mar 24, 2023 · 3 comments · Fixed by #2487

Comments

@KonstantinEpam23
Copy link
Collaborator

Background
We are currently using rollup.js for building the project, this library seems to be outdated and we have problems with builds taking too much time.

Solution
We would like to switch to a different build library, vite.js seems like a good solution: https://vitejs.dev

  • it uses the same cli and plugin apis that are used by rollup.js, so the switch should not be too hard in terms of code changes
  • it promises big gains in build time

Alternatives

  • switching to other build engines

Additional context
As part of this ticket, we would like to try and switch the build process from using rollup to using vite, this will involve updating all package.json files across ./packages and ./example and testing the local build timing on various systems

@yuleicul
Copy link
Collaborator

yuleicul commented Mar 24, 2023

Hi 👋 I have a question here. I just did some research, and I found Vite does provide a faster development experience because it supports unbundled ESM in development. As for production, it uses Rollup to bundle the code under the hood.

The Ketcher codebase is a monorepo If I understand correctly, so we have to build packages every time we develop. Every time we develop in localhost, we should run yarn start (npm start after #2008) in /packages/ketcher-core, /packages/ketcher-react and so on. In /packages/ketcher-core/package.json we can see yarn start equals to rollup --watch which means we just watch the new change and bundle with Rollup again.

If I replace Rollup with Vite, I'd probably want to make npm start equal to something like vite build --watch which runs rollup under the hood, so we are not gonna have the faster development experience because we don't use vite dev.

Maybe I'm wrong, but If there are some ways we can use vite dev when developing in a monorepo, then I believe the development experience will level up. Or maybe vite build can reduce the build time as expected.

@yuleicul
Copy link
Collaborator

yuleicul commented Mar 27, 2023

(This is an investigation diary, not a final proposal)

My plan to switch to Vite is:

For /packages

  1. Rewrite rollup.config.js to vite.config.js
  2. Update scripts: 
    "build": "cross-env NODE_ENV=production rollup -c -m true"--> "build": "cross-env NODE_ENV=production vite build"
    "start": "cross-env NODE_ENV=development rollup -c -m true -w" --> "start": "cross-env NODE_ENV=development vite build -w"

For /example:

  1. Replace react-app-rewired with Vite
  2. Add new vite.config.js

What I'm doing today is try to rewrite rollup.config.js to vite.config.js in ketcher-core. It's a bit tough because some rollup plugins are not compatible in vite. My next step is to figure out what every plugin does and try to find a vite plugin to replace it. And also I hit some pitfalls.... for example, we use paths in tsconfig to map some paths, but vite doesn't recognize them.

My estimate for the whole switch is 5 days. Next week we have a public holiday on Wed, and I want to take two more regular vacations on Mon and Tue. So I'll try to finish by the end of this Friday.

@yuleicul
Copy link
Collaborator

yuleicul commented Mar 28, 2023

(This is an investigation diary, not a final proposal)

Have successfully moved to Vite in ketcher-core, but the build speed is almost the same as before.

Today I was working on rewriting rollup.config.js to vite.config.js in ketcher-react, but I hit some pitfalls. Just trying to resolve them. (Vite has a lot of built-in plugins)

What enlightened me is

This is just a PoC, may be you don't need to support all the plugins we have or some other stuff to do.
We just need to understand:
– Is it possible to migrate to other tool?
– If yes, what benefits we will receive?
– If no, then why? And what needs to be done to become "yes"
-- @Nitvex

So I think I need to change my mind. My plan for tomorrow:

yuleicul added a commit that referenced this issue Mar 31, 2023
yuleicul added a commit that referenced this issue Apr 6, 2023
yuleicul added a commit that referenced this issue Apr 11, 2023
@KonstantinEpam23 KonstantinEpam23 changed the title [INVESTIGATION] Move to vite from rollup for project build Move to vite from react-app-rewired for example project development build Apr 12, 2023
yuleicul added a commit that referenced this issue Apr 14, 2023
yuleicul added a commit that referenced this issue Apr 14, 2023
yuleicul added a commit that referenced this issue Apr 14, 2023
yuleicul added a commit that referenced this issue Apr 14, 2023
yuleicul added a commit that referenced this issue Apr 17, 2023
yuleicul added a commit that referenced this issue Apr 18, 2023
yuleicul added a commit that referenced this issue Apr 18, 2023
yuleicul added a commit that referenced this issue Apr 18, 2023
@Nitvex Nitvex added this to the Ketcher 2.10.0-rc.1 milestone Apr 20, 2023
yuleicul added a commit that referenced this issue Apr 25, 2023
Nitvex pushed a commit that referenced this issue Apr 28, 2023
…ment build (#2487)

* #2411 - Add new Vite based command  to example for development

* #2411 - Add icons to entry html

* #2411 - Ignore dist/index.css

* #2411 - Fix dropdown icon of tool to show

* #2411 - Fix class variable members being assigned `undefined` when initialization

* #2411 - Fix uncaught referenceError - cannot access 'clientX' before initialization

* #2411 - Eject webpack env to vite

* #2411 - Replace CommonJS with ESM

* #2411 - Add dev tsconfig for ketcher-core TS intelliSense

* #2411 - Refactor customResolver to resolve same aliases from different packages

* #2411 - Update Vite entry to public/index.html

* #2411 - Fix dist files not containing index.d.ts

* #2411 - Ignore warning which shouldn't be warned

* #2411 - Fix duplicated imports

* #2411 - Add paths to tsconfig to enable ketcher-core TS intelliSense

* Revert "#2411 - Fix duplicated imports"

This reverts commit 0a0c451.

* Revert "#2411 - Replace CommonJS with ESM"

This reverts commit 52acf6d.

* #2411 - Replace commonJS with dynamic ESM

* Revert "#2411 - Replace commonJS with dynamic ESM"

This reverts commit ad5577a.

* #2411 - Replace commonjs with dynamic ESM

* #2411 - Fix missing CSS source file warning

* #2411 - Add comment to vite alias config

* #2411 - Upgrade Vite to 4.3.1

* #2411 - Update Vite to new patch version
@github-project-automation github-project-automation bot moved this to Done in Ketcher Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment