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

Keep the build output in the repository to avoid building on the cloud #1226

Open
nikkothari22 opened this issue Jan 5, 2025 · 6 comments
Open

Comments

@nikkothari22
Copy link
Member

nikkothari22 commented Jan 5, 2025

All SPA apps using Frappe have a build step that does the following:

  1. Build the Vue/React SPA and store the output JS/CSS/other assets in the Frappe apps's public directory
  2. Copy the generated index.html file to the <app>.html file

This is done for all deployments since the generated build output and the index.html files are ignored in git. My question is : why?

I am almost 90% sure that I'm missing something extremely stupid here, but why not just build the app and keep the build output in the repo itself? That way, we don't need to build the app again on the server. This would save (potentially) thousands of hours of build times across apps across multiple benches.

Will check if this works. If anyone has any idea why this won't work, please feel free to share. I'm already convinced that I am missing something basic here.

Copy link

linear bot commented Jan 5, 2025

@nikkothari22
Copy link
Member Author

Some additional research:

Why do projects like Vue/Three.js check build results to git
This states to not have build output in source because code reviews become complicated - I agree.

What if code review remains the same but on every push to the main branch, a GitHub action creates a pull request with the build output - sort of like a "release PR"?

@nikkothari22
Copy link
Member Author

It's easier to think this in terms of npm packages - which are compiled and then uploaded to npm. Frappe apps are sort of like javascript packages - the end users just want to download it and then update their database. Why "build" any frontend assets?

@nikkothari22
Copy link
Member Author

nikkothari22 commented Jan 5, 2025

Updates from my test:

I created a new branch called "build-output-trial" which has the entire build output stored in Git in the Frappe app repo. I just changed one line of text in the UI to test if I get the new build or not.

Previous identical deployment on FC took 305 seconds just for Raven:

image

New deployment with the build output stored and removing the build step from package.json took 126 seconds (60% faster)

image

And it took that much time since yarn install still ran for the React app - even that could be eliminated.

The more I think about it, the more it makes sense. This would allow us to use Vite 5 without being dependent on the end user's node version. For example, the mobile app branch requires a minimum node version of 18.18 because of the Metro bundler. It's far easier to just "publish" the app instead of asking users to build it.

@netchampfaris
Copy link

@nikkothari22

I think the idea of "build once" and "download everywhere" makes a lot of sense.

Frappe Framework did a version of this where built assets are uploaded to GitHub assets and then downloaded when "bench build" command is run.

Now, your approach of committing build output to the repo eliminates unnecessary steps. I think this should be first-class for every Frappe app.

@nikkothari22
Copy link
Member Author

One problem with this approach is that merging branches (let's say develop -> main) might become an issue since the build outputs might have merge conflicts and there's no way to meaningfully resolve them.

I wonder if there's a way to tell git to ignore certain files... oh wait 🤔

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

No branches or pull requests

2 participants