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

HMR at Module Federation #8

Closed
ckken opened this issue Nov 9, 2020 · 17 comments
Closed

HMR at Module Federation #8

ckken opened this issue Nov 9, 2020 · 17 comments

Comments

@ckken
Copy link
Contributor

ckken commented Nov 9, 2020

module-federation/module-federation-examples#358

@ckken
Copy link
Contributor Author

ckken commented Dec 10, 2020

esbuild & swc is work,babel throw error

@ruanyl
Copy link

ruanyl commented May 25, 2021

The root cause of HMR not working when doing module federation is that the remoteEntry.js is included in the index.html by default.

Check out the comment here: module-federation/module-federation-examples#358 (comment)
And here: module-federation/module-federation-examples#358 (comment)

To fix the problem, only include the chunks that you need in HtmlWebpackPlugin. In emp's case, it will be chunks: ['index']

@ckken
Copy link
Contributor Author

ckken commented May 26, 2021

The root cause of HMR not working when doing module federation is that the remoteEntry.js is included in the index.html by default.

Check out the comment here: module-federation/module-federation-examples#358 (comment)
And here: module-federation/module-federation-examples#358 (comment)

To fix the problem, only include the chunks that you need in HtmlWebpackPlugin. In emp's case, it will be chunks: ['main']

is there demo?

@flyyuan
Copy link
Contributor

flyyuan commented May 26, 2021

remark

@ruanyl
Copy link

ruanyl commented May 26, 2021

@ckken So just add this to HtmlWebpackPlugin args

chunks: ['index']

@ckken
Copy link
Contributor Author

ckken commented May 26, 2021

@flyyuan
Copy link
Contributor

flyyuan commented May 26, 2021

me too. no work

@ruanyl
Copy link

ruanyl commented May 26, 2021

Could chunks override somewhere? What I'm doing is just use emp-cli to create a react project, and I add it to emp-config.js. And also the name of the chunk depends on your entry in your config.

  config.plugin("html").tap((args) => {
    args[0] = {
      ...args[0],
      ...{
        title: "EMP REACT BASE",
        files: {},
        chunks: ["index"],
      },
    };
    return args;
  });

And it works fine for me as you can see in the screenshot, the HMR is working.

image

@flyyuan
Copy link
Contributor

flyyuan commented May 26, 2021

your page had an update after HMR?

@ruanyl
Copy link

ruanyl commented May 26, 2021

@flyyuan For sure, that's the whole point, isn't it?

@ckken
Copy link
Contributor Author

ckken commented May 26, 2021

hmr main problem in module federation when project expose some modules, when you haven't expose, hmr is work!

@ruanyl
Copy link

ruanyl commented May 26, 2021

@ckken Yeah, but that's the symptom. Have you checked my comment on the other issue I linked above? module-federation/module-federation-examples#358 (comment)

So when you have exposed modules, ModuleFederationPlugin generates remoteEntry.js for you(file name is based on the config). And by default, all js assets will be injected to index.html, including remoteEntry.js.
But remoteEntry.js is not needed when running the current application. It's only required by the other federated applications which refer to it via remotes.

@ckken
Copy link
Contributor Author

ckken commented May 26, 2021

@ckken Yeah, but that's the symptom. Have you checked my comment on the other issue I linked above? module-federation/module-federation-examples#358 (comment)

So when you have exposed modules, ModuleFederationPlugin generates remoteEntry.js for you(file name is based on the config). And by default, all js assets will be injected to index.html, including remoteEntry.js.
But remoteEntry.js is not needed when running the current application. It's only required by the other federated applications which refer to it via remotes.

yes,I saw~ but the error is not caused here

@ruanyl
Copy link

ruanyl commented May 26, 2021

@ckken Alright, so you're referring to some other issue. I see you link the issue here, I thought it might be the same issue I encountered.

@ckken
Copy link
Contributor Author

ckken commented Jul 19, 2021

fixed it in @efox/emp-cli 1.8.26 may be!?

@ckken
Copy link
Contributor Author

ckken commented Jul 19, 2021

hot reload for react update @efox/emp-react to v1.1.6

@ckken
Copy link
Contributor Author

ckken commented Jul 21, 2021

@ckken ckken closed this as completed Jul 21, 2021
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

3 participants