Skip to content

Conversation

@pi0
Copy link

@pi0 pi0 commented Oct 24, 2025

Context: In nitro, we bundle most of plugin dependencies. This causes an issue with using fullastack plugin in end projects:

Error: Cannot find module 'virtual:fullstack/runtime' imported from '/home/pooya/Code/nitro-vite-examples/examples/vue-router-ssr/src/entry-client.ts'


This PR fixes the limitation by exposing small set of runtime utils as a virtual entry instead.

I have preserved other /runtime subpath for external usage without breaking change.

Copy link
Owner

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Good point. My intent of #1285 was achieving that, but apparently it wasn't fully done. Thanks

Comment on lines 843 to 862
// virtual:fullstack/runtime
function runtimeUtils() {
return /* js */ `
export function mergeAssets(...args) {
const js = uniqBy(args.flatMap((h) => h.js), (a) => a.href);
const css = uniqBy(args.flatMap((h) => h.css), (a) => a.href);
const entry = args.filter((arg) => arg.entry)?.[0]?.entry;
const raw = { entry, js, css };
return { ...raw, merge: (...args$1) => mergeAssets(raw, ...args$1) };
}
function uniqBy(array, key) {
const seen = new Set();
return array.filter((item) => {
const k = key(item);
if (seen.has(k)) return false;
seen.add(k);
return true;
});
}`;
}
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, however copying the code string here is not ideal. Let me think.

Comment on lines +374 to +379
if (id === "\0virtual:fullstack/runtime") {
return fs.readFileSync(
path.join(import.meta.dirname, "runtime.js"),
"utf-8",
);
}
Copy link
Owner

Choose a reason for hiding this comment

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

@pi0 How about this? I think nft style bundling supports something like this, but is nitro itself bundled to support this?

Copy link
Author

@pi0 pi0 Oct 28, 2025

Choose a reason for hiding this comment

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

This will cause pulling in extra dependencies to dist/node_modules + extra dist as nft cannot tree-shake code by imports anymore. I have noticed plugin depends on srvx 0.8 for example it was tracing both 0.8 and 0.9!

Maybe later we can have a build step to convert runtime.ts into inlined code?

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.

2 participants