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

Bundle frontend app #15

Merged
merged 3 commits into from
Jun 17, 2024
Merged

Bundle frontend app #15

merged 3 commits into from
Jun 17, 2024

Conversation

huchenlei
Copy link
Member

@huchenlei huchenlei commented Jun 15, 2024

This PR makes ComfyUI frontend bundled as a normal web app, while being backward compatible with the exsiting extension ecosystem.

The solution is to add a shim layer with custom vite plugin. All existing exports from all source files will be write to window.comfyAPI.{module name}.{export symbol} and shim function will create .js shim file at the original module's location to re-export bindings on window object so that extention code still perceives these modules.

Example generated shim file dist/scripts/app.js:

// Shim for scripts\app.ts
export const ANIM_PREVIEW_WIDGET = window.comfyAPI.app.ANIM_PREVIEW_WIDGET;
export const ComfyApp = window.comfyAPI.app.ComfyApp;
export const app = window.comfyAPI.app.app;

Example generated code to write to window.comfyAPI:

window.comfyAPI = window.comfyAPI || {};
window.comfyAPI.app = window.comfyAPI.app || {};
window.comfyAPI.app.ANIM_PREVIEW_WIDGET = ANIM_PREVIEW_WIDGET;
window.comfyAPI.app.ComfyApp = ComfyApp;
window.comfyAPI.app.app = app$1;

TODO

  • Verify that generated code works well when content in dist/ is placed under web/ in main comfyui repo
  • Adjust existing tests to accept this change

@huchenlei
Copy link
Member Author

Note:

The jest mocking no longer works because everything now is bundled. We need to find another way to hijack the api behaviour.

@huchenlei
Copy link
Member Author

Note:

The jest mocking no longer works because everything now is bundled. We need to find another way to hijack the api behaviour.

Test issue solved in https://github.com/huchenlei/ComfyUI_frontend/pull/19

@huchenlei huchenlei merged commit b794d96 into main Jun 17, 2024
2 checks passed
@huchenlei huchenlei deleted the bundle branch June 17, 2024 16:18
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