File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ import type { Plugin , PluginOption } from "vite" ;
2+
3+ interface ClientOnlyPluginsOptions {
4+ filter : string [ ] ;
5+ }
6+
7+ export function clientOnlyPlugins ( options : ClientOnlyPluginsOptions ) : Plugin {
8+ function makePluginClientOnly ( plugin : PluginOption ) {
9+ if ( typeof plugin !== "object" || ! plugin ) return ;
10+ if ( Array . isArray ( plugin ) ) return plugin . forEach ( makePluginClientOnly ) ;
11+ if ( "then" in plugin ) return void plugin . then ( makePluginClientOnly ) ;
12+ if ( ! options . filter . includes ( plugin . name ) ) return ;
13+ Object . assign ( plugin , { applyToEnvironment } ) ;
14+ }
15+
16+ return {
17+ name : "comiacapay:client-only-plugins" ,
18+ config ( config , _env ) {
19+ makePluginClientOnly ( config . plugins ) ;
20+ } ,
21+ } ;
22+ }
23+
24+ function applyToEnvironment ( environment : { name : string } ) {
25+ return environment . name === "client" ;
26+ }
Original file line number Diff line number Diff line change 11import { reactRouter } from "@react-router/dev/vite" ;
22import { defineConfig } from "vite" ;
33import { VitePWA } from "vite-plugin-pwa" ;
4+ import { clientOnlyPlugins } from "./plugins/client-only-plugins" ;
45import vercelCustomEntrypoint from "./plugins/vercel-custom-entrypoint" ;
56
67export default defineConfig ( {
@@ -43,6 +44,7 @@ export default defineConfig({
4344 outDir : "build/client" ,
4445 } ) ,
4546 vercelCustomEntrypoint ( { main : "./main.ts" } ) ,
47+ clientOnlyPlugins ( { filter : [ "vite-plugin-pwa:build" ] } ) ,
4648 ] ,
4749 resolve : {
4850 tsconfigPaths : true ,
You can’t perform that action at this time.
0 commit comments