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

Support GetPublicPath from federation options #104

Open
judithhartmann opened this issue Sep 25, 2024 · 14 comments · Fixed by #108
Open

Support GetPublicPath from federation options #104

judithhartmann opened this issue Sep 25, 2024 · 14 comments · Fixed by #108
Labels
enhancement New feature or request

Comments

@judithhartmann
Copy link
Contributor

Currently setting getPublicPath in the plugin config seems to have no effect (I could not find the function i passed there anywhere in my build output).

Expected behaviour described here:
https://module-federation.io/configure/getpublicpath.html

@zhangHongEn
Copy link
Contributor

understand

@gioboa gioboa added enhancement New feature or request COMMUNITY: PR is welcomed We think it's a good feature to have but would love for the community to help with the PR for it labels Sep 25, 2024
@gioboa gioboa removed the COMMUNITY: PR is welcomed We think it's a good feature to have but would love for the community to help with the PR for it label Sep 26, 2024
@gioboa
Copy link
Collaborator

gioboa commented Sep 26, 2024

@judithhartmann we are working on it. can you create an example based on this example of these special config pls?
You can post here the changes I guess. Thanks, this will help us a lot.

@judithhartmann
Copy link
Contributor Author

I will.

I also saw in your PR that there seems to be a static public path option that i did not find in the docs, I will try that as well.

The issue i ran into my project is that we have the modules in a cdn but the remoteEntry was trying to load the get from a relative path, that of course did not match the actual location of that filw

@gioboa
Copy link
Collaborator

gioboa commented Sep 26, 2024

Thanks, with your example we can certify the new implementation 👏

@judithhartmann
Copy link
Contributor Author

judithhartmann commented Sep 28, 2024

I tried to build an example from your PR #108, unfortunately i got stuck because getPublicPath does not seem to be applied.

I would assume i'll find something related to it in the build output of the remote.
i basically just set getPublicPath: `function () { return 'http://localhost:4001/custom-prefix/'}`, in the remote, but i could not find '/custom-prefix' in the output at all.
if it works i would find some traces of it right?

@gioboa
Copy link
Collaborator

gioboa commented Sep 28, 2024

Yep, the PR it's not complete yet. I was waiting for the test case. Can you share with me your configurations please ?


It's
getPublicPath: function () { return 'http://localhost:4001/custom-prefix/'}
right? How can I test of it's working or not?

@judithhartmann
Copy link
Contributor Author

judithhartmann commented Sep 28, 2024

Here are all my modifications
judithhartmann@01502f5

I modified the vite dev and preview server, so they will serve all files with the /custom-prefix as well, without using base.

Basically the test would be, that every file requested from the host from this remote (not just remoteEntry.js) also contains the custom prefix.

@gioboa
Copy link
Collaborator

gioboa commented Oct 1, 2024

@judithhartmann I'm wondering if we can consider using the Vite experimental.renderBuiltUrl configuration instead of supporting the getPublicPath option.

@judithhartmann
Copy link
Contributor Author

it looks like this might work

however, from user perspective, since since plugin does not have it's own extensive docs, but relies on https://module-federation.io/ it might be confusing, as getPublicPath is documented over there to achieve this behaviour

@gioboa
Copy link
Collaborator

gioboa commented Oct 2, 2024

Yup, you are right, we can add a section in the README for that. Would you like to drop a PR for that?

@gioboa
Copy link
Collaborator

gioboa commented Oct 2, 2024

I added a warning
This is nice for the DX. @judithhartmann Can you verify that that Vite config is solving the case pls?

@zhangHongEn
Copy link
Contributor

zhangHongEn commented Oct 4, 2024

Even if experimental.renderBuiltUrl is set, manifest.json still needs to have getPublicPath, and they need to work together. I’ve restored the code.

@judithhartmann
Copy link
Contributor Author

Hi @gioboa, sorry for the delay.

I tried out the experimental.renderBuiltUrl. (Branch)

  experimental: {
    renderBuiltUrl: (filename) => {
      return `http://localhost:4001/custom-prefix/${filename}`;
    },
  },

Unfortunately the only place where i can find the custom-prefix in the built output is in the index.html, so it does not have an influence on the remotyEntry.js nor any files related to it.

In the vite dev example, all files aside from the remoteEntry.js where loaded without the prefix

combined with @zhangHongEn concerns, i think we need to reopen this.

@judithhartmann
Copy link
Contributor Author

if i set the base in the vite config (which works for static paths), i can see the custom-prefix here in dist/assets/virtual_mf-exposes-[HASH.js. probably getPublichPath should have an influence on this one as well.

const assetsURL = function(dep) { return "/custom-prefix/"+dep };

@gioboa gioboa reopened this Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants