đ„¶ vite-plugin-stripper
The first need was to remove @BackendMethod from your browser bundle for
remult.
How it works
Section titled âHow it worksâVite already gives you import.meta.env.SSR - a constant thatâs true on
the server and false in the client bundle. Wrapping a block in
if (import.meta.env.SSR) { ... } lets the client tree-shaker drop the
whole block at build time:
function readSecret() { if (import.meta.env.SSR) { // stripped from the client bundle return process.env.AUTH_SECRET }}vite-plugin-stripper automates that wrapping for decorator-based code
(like remultâs @BackendMethod and @Entity server-only callbacks) so
you donât have to sprinkle if (import.meta.env.SSR) by hand on every
method.
Installation
Section titled âInstallationânpm i -D vite-plugin-stripperQuick start
Section titled âQuick startâimport { sveltekit } from '@sveltejs/kit/vite'import { defineConfig } from 'vite'import { stripper } from 'vite-plugin-stripper'
export default defineConfig({ plugins: [ stripper(), // đ uses the default config sveltekit(), ],})Calling stripper() with no arguments applies defaultStripConfig, which
covers the common remult setup:
// equivalent to: stripper()import { defaultStripConfig, stripper } from 'vite-plugin-stripper'
stripper({ strip: defaultStripConfig })defaultStripConfig is:
;[ { decorator: 'BackendMethod' }, { decorator: 'Entity', args_1: [ { fn: 'backendPrefilter' }, { fn: 'backendPreprocessFilter' }, { fn: 'sqlExpression' }, { fn: 'saved' }, ], },]Extending the default
Section titled âExtending the defaultâimport { defaultStripConfig, stripper } from 'vite-plugin-stripper'
stripper({ strip: [...defaultStripConfig, { decorator: 'MyCustomServerOnly' }],})Custom configuration
Section titled âCustom configurationâstripper({ strip: [ { decorator: 'BackendMethod' }, { decorator: 'Entity', args_1: [ { fn: 'backendPrefilter' }, { fn: 'sqlExpression' }, { fn: 'saved', // keep `saved` for these specific entities, strip it everywhere else excludeEntityKeys: ['users'], }, ], }, ],})Nullify imports
Section titled âNullify importsâYou can also drop entire imports from the client bundle (import { X } from 'pkg'
becomes let X = null):
stripper({ nullify: ['mongodb', '$env/static/private'],})