-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[🐞] Tree shaking doesn't work for qwik libraries using the recommended build script #5097
Comments
Argh! That is a good one! I looked into why all of the symbols are retained, and it is because they are all referenced, so the rollup is doing the right thing. The question is, why are they all referenced? The issue is that qwik-ui library has components, and each component has a listener hence a QRL. Qwik does not know if any one QRL is being used so it sides on the side of caution and generates entry points for them anyway. But those entry points end up pulling in all of the So this is a Qwik optimizer issue (not a mistake in how qwik-ui has been bundled.) |
update: tried to change the config to "preserve modules" and output a file for each source file Didn't work, it fails on loading some qrls now should I create a different issue? or just a detailed comment here? |
I think it is related so just add it here.... |
Using So using rollupOptions: {
output: {
preserveModules: true,
preserveModulesRoot: 'packages/kit-headless/src',
},
}, if the library has a component$ named Maybe we could resolve those namespace conflicts with the optimizer? And then have P.S. To see the import { defineConfig } from "vite";
import { qwikVite } from "@builder.io/qwik/optimizer";
import { qwikCity } from "@builder.io/qwik-city/vite";
import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig(() => {
let rollupOptions = {};
if (process.env.npm_lifecycle_event === "build.client") {
// Client-specific configuration
rollupOptions = {
output: {
// Customize the client build structure
entryFileNames: (fileInfo:any) => {
return `build/[name]-[hash].js`
},
chunkFileNames: (fileInfo:any) => {
return `build/[name]-[hash].js`
},
assetFileNames: `build/[name]-[hash].[ext]`,
},
};
}
return {
build: {
rollupOptions,
},
preview: {
headers: {
"Cache-Control": "public, max-age=600",
},
},
plugins: [qwikCity(), qwikVite(), tsconfigPaths()],
};
}); It outputs the build files as
instead of
P.S. #2: Repro and steps in qwikifiers/qwik-ui#519 |
FWIW, if I pnpm uninstall the library and copy/paste the code, the error is gone, but then I lose the benefits of using a library. The interesting bit is that when I have a duplicate component in a Qwik project (that is not coming from an external library), the optimizer creates two symbols for the components and attaches them to the same entry. Repro: https://github.com/maiieul/qwik-component-duplicate I'm using Steps:
I can create another issue with this repro if this is of concern. |
Hey @shairez I believe this has been solved. Can we close this? |
I'm not sure this can be marked as fixed unless we add something like output: {
preserveModules: true,
preserveModulesRoot: '/src',
}, to the default vite.config of the library mode starter of The problem is that |
Which component is affected?
Qwik Rollup / Vite plugin
Describe the bug
Out of the box, Qwik's build script for the "library" starter (component library for example) produces one big
index.qwik.mjs
(and.cjs
) containing ALL of the library code.When consuming the library from a qwik app project, ALL of the library is getting built into one big chunk and getting prefetched (and not only the used code from that library).
Here's a real life example of this bug:
qwikifiers/qwik-ui#384
POSSIBLE SOLUTIONS:
Fix the tree shaking so it'll only consume the imported parts from the
index.qwik.mjs
Change the default way libs are getting built in by outputting individual js files for each library file (instead of a giant index file)
Reproduction
https://github.com/shairez/qwik-ui-headless-import-issue-384
Steps to reproduce
pnpm preview
Accordion
was used.System Info
Additional Information
POSSIBLE SOLUTIONS:
Fix the tree shaking so it'll only consume the imported parts from the
index.qwik.mjs
Change the default way libs are getting built in by outputting individual js files for each library file (instead of a giant index file)
The text was updated successfully, but these errors were encountered: