Skip to content

Commit

Permalink
chore: vitePluginSilenceUseClientBuildWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Mar 29, 2024
1 parent 35ec0c5 commit e6cbf0f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/react-server/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default defineConfig((env) => ({
name: "react-server",
}),
vitePluginFixJsxDEV(),
vitePluginSilenceUseClientBuildWarning(),
],

environments: {
Expand Down Expand Up @@ -213,3 +214,36 @@ function createVirtualPlugin(name: string, load: Plugin["load"]) {
},
} satisfies Plugin;
}

function vitePluginSilenceUseClientBuildWarning(): Plugin {
return {
name: vitePluginSilenceUseClientBuildWarning.name,
apply: "build",
enforce: "post",
config: (config, _env) => ({
build: {
rollupOptions: {
onwarn(warning, defaultHandler) {
if (
warning.code === "SOURCEMAP_ERROR" &&
warning.message.includes("(1:0)")
) {
return;
}
if (
warning.code === "MODULE_LEVEL_DIRECTIVE" &&
warning.message.includes(`"use client"`)
) {
return;
}
if (config.build?.rollupOptions?.onwarn) {
config.build.rollupOptions.onwarn(warning, defaultHandler);
} else {
defaultHandler(warning);
}
},
},
},
}),
};
}

0 comments on commit e6cbf0f

Please sign in to comment.