Address Vite warnings in build step #193
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that Vite shows a few warning messages when running the build step. These few changes clear those messages and should also improve chunking via rollup.
- Error
(!) bulletproof-react/apps/react-vite/src/app/routes/app/users.tsx is dynamically imported by bulletproof-react/apps/react-vite/src/app/routes/index.tsx but also statically imported by bulletproof-react/apps/react-vite/src/app/routes/index.tsx, dynamic import will not move module into another chunk.
- Solution
The loaders for discussions and users need to be in a separate file. Since the page components are being dynamically imported in the router, the static imports for the loaders generate this warning which ends up creating larger chunks sizes.
- Error
src/components/ui/dialog/dialog.tsx (1:0): Error when using sourcemap for reporting an error: Can't resolve original location of error.
- Solution
Remove "use client" from the dialog component.
- Error
Module "fs/promises" has been externalized for browser compatibility, imported by "bulletproof-react/apps/react-vite/src/testing/mocks/db.ts". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
- Solution
This isn't really an issue other than the error message, but you can prevent it by externalizing
fs/promises
viarollupOptions
in the vite config- Error
Some chunks are larger than 500 kB after minification. Consider: Using dynamic import() to code-split the application, Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks, Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
- Solution
Fixing the dynamic/static import loader issue gets the chunk size down a bit.
@alan2207 Thanks again for the great project, it has been really helpful for improving my project structures!