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

Vite: Silence "use client" build warnings #8897

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quick-experts-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Vite: Silence build warnings when dependencies include "use client" directives
23 changes: 23 additions & 0 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,27 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
)
);

let baseRollupOptions = {
// Silence Rollup "use client" warnings
// Adapted from https://github.com/vitejs/vite-plugin-react/pull/144
onwarn(warning, defaultHandler) {
if (
warning.code === "MODULE_LEVEL_DIRECTIVE" &&
warning.message.includes("use client")
) {
return;
}
if (viteUserConfig.build?.rollupOptions?.onwarn) {
viteUserConfig.build.rollupOptions.onwarn(
warning,
defaultHandler
);
} else {
defaultHandler(warning);
}
},
} satisfies Vite.BuildOptions["rollupOptions"];

return {
__remixPluginContext: ctx,
appType:
Expand Down Expand Up @@ -1011,6 +1032,7 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
manifest: true,
outDir: getClientBuildDirectory(ctx.remixConfig),
rollupOptions: {
...baseRollupOptions,
preserveEntrySignatures: "exports-only",
input: [
ctx.entryClientFilePath,
Expand All @@ -1035,6 +1057,7 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
manifest: true, // We need the manifest to detect SSR-only assets
outDir: getServerBuildDirectory(ctx),
rollupOptions: {
...baseRollupOptions,
preserveEntrySignatures: "exports-only",
input: serverBuildId,
output: {
Expand Down