Description
Feature request
Tree-shaking is currently not possible with the supabase-js library because SupabaseClient
is implemented using classes. Neither Webpack or Rollup supports tree-shaking class methods.
Is your feature request related to a problem? Please describe.
Supabase bundle size is quite small compared to others (firebase, amplify), but it will only increase as more features are added. Projects that do not use all the features that Supabase provides will regardless pay the cost. Firebase has realized this with their new Modular Javascript SDK.
Describe the solution you'd like
Instead of initializing a single Supabase client, here's a modular API proposal:
// initSupabase.js
const supabaseClient = createClient(supabaseUrl, supabaseKey);
// Does not automatically instantiate RealtimeClient, PostgrestClient, etc.
// Features can be opted in as such:
export const db = getPostgrest(supabaseClient);
export const realtime = getRealtime(supabaseClient);
export const auth = getAuth(supabaseClient);
export const storage = getStorage(supabaseClient);
// some-random-component.js
import { db, realtime } from './initSupabase';
const { data, error } = await db
.from('cities')
.select()
const mySubscription = realtime
.from('*')
.on('*', payload => {
console.log('Change received!', payload)
})
.subscribe()
While this won't eliminate every piece of unused code, it's a start to enabling opt-in for specific features.
Caveats
- Will break the current stable API, but can be remedied w/ codemods.
- Not sure if
SupabaseAuthClient
can be separated as all other modules rely on that
If this is something you guys think is worth pursuing, I'd be happy to start working on a PR!