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

example: Hotreloading Type Declerations #113

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

Conversation

econneely
Copy link

Repo example for #112
Docs here https://module-federation.io/configure/dts.html

Expected a the host to generate a @mf-types/ as described in here https://module-federation.io/guide/basic/type-prompt.html

@@ -6,7 +7,7 @@ import './index.css';
import viteLogo from '/vite.svg';

const RemoteButton = lazy(() => import('remote/Button'));
const WebpackButton = lazy(() => import('webpack/Image'));
const WebpackButton = lazy(() => loadRemote('webpack/Image'));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import logo from './assets/webpack-logo.png';

const WebpackImage = () => {
const WebpackImage = ({ foo }: { foo: number }) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing types on the component in host

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know its jsx but it can still use and should have the @mf-types/ folder extracted

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The foo: number is added for example

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍 it helps a lot

@@ -69,6 +69,14 @@ module.exports = {
name: 'webpack',
filename: 'remoteEntry.js',
remotes: {},
dts: {
generateTypes: true,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this you can see it creates a dist folder with the types that should be synced to the folder in host

@gioboa gioboa changed the title Example repo example: Hotreloading Type Declerations Sep 26, 2024
@gioboa
Copy link
Collaborator

gioboa commented Sep 27, 2024

The @module-federation/enhanced is doing

if (options.dts !== false) {
  new DtsPlugin(options).apply(compiler);
}

so I think we need to do the same

dts: {
consumeTypes: true,
},
dev: true,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://module-federation.io/configure/dev.html some relevent options for types hot reloading too

@gioboa
Copy link
Collaborator

gioboa commented Sep 27, 2024

We can't use new DtsPlugin(options).apply(compiler); because from my understanding apply needs a Webpack compiler.
@ScriptedAlchemy is it correct?

@ScriptedAlchemy
Copy link
Member

Yes, but the DTS manager itself is agnostic and could be implemented in other bundlers.

@ScriptedAlchemy
Copy link
Member

ScriptedAlchemy commented Oct 4, 2024

My colleague is on leave this week, but he understands the DTS system best. It's quite intricate, but there's a DTS manager that should create a separate server for handling type requests and builds. We can also register dynamic remote types from the browser by sending the data back to the DTS server, which then generates the discovered types.
It shouldn't be tightly coupled to any bundler, but it still has a few moving parts.

@gioboa
Copy link
Collaborator

gioboa commented Oct 4, 2024

My colleague is on leave this week, but he understands the DTS system best. It's quite intricate, but there's a DTS manager that should create a separate server for handling type requests and builds. We can also register dynamic remote types from the browser by sending the data back to the DTS server, which then generates the discovered types. It shouldn't be tightly coupled to any bundler, but it still has a few moving parts.

I'm creating a "generic compiler" that is implementing all the methods needed 😉

@ScriptedAlchemy
Copy link
Member

Perfect. You can send a pr back to core if additional changes or packages need to be created for dts to support other tools

@gioboa gioboa marked this pull request as draft October 21, 2024 09:39
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.

3 participants