Replies: 2 comments
|
The distinction is between importing something and actually using it. Adding a named import to every file doesn’t necessarily retain that binding However, “used somewhere in the application” doesn’t mean “included in every There are also side-effect considerations: importing a module can execute So your approach might produce equivalent output, but I wouldn’t assume that Relevant docs: |
|
There are a few separate problems in the middleware:
Do the API check and choose the destination before passing control to the configureServer(server) {
server.middlewares.use(async (req, res, next) => {
if (req.url !== "/incoming") {
return next();
}
try {
const response = await fetch(api);
if (response.status === 400) {
res.statusCode = 500;
res.end("Upstream API rejected the request");
return;
}
// Choose the existing destination or fallback here.
req.url = "/try/incomingIfExists";
return next();
} catch (error) {
return next(error);
}
});
}The remaining question is what “exists” means here. Are |
Uh oh!
There was an error while loading. Please reload this page.
I develop my websites using Qwik. Let's say a website is made of 100 components. I know that I will import all of these items somewhere:
In other words, when I finish my website and provide a distinct list of all of the imports from Qwik + Qwik City libraries at the top of my files, I end up with that list.
Those are used in all of my websites. Because of my architecture, I definitely use them.
Now, my question is this. What happens if I create a Vite pre-plugin that imports all of them at the top of every file? Is there any downside? After all, they are all included somewhere, so if I understand it correctly, then they are all included in the final bundle and won't be tree-shaken.
All reactions