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

[RFC] Option-driven tree-shaking toggles #74

Open
aleclarson opened this issue Jul 3, 2022 · 0 comments
Open

[RFC] Option-driven tree-shaking toggles #74

aleclarson opened this issue Jul 3, 2022 · 0 comments
Labels
proposal An idea not set in stone roadmap

Comments

@aleclarson
Copy link
Contributor

aleclarson commented Jul 3, 2022

The Problem

There's no simple way to include code in client/server bundle only when a specific plugin/framework option has a specific value at build time.

Example

In any Vite-compiled module:

// @toggle foo
callSomeFunction(...args)

The foo toggle should be registered with Saus at build time:

export function MySausPlugin(options) {
  return {
    name: 'my-saus-plugin',
    saus({ toggles }) {
      // The `foo` option of my plugin decides if "foo" toggle is removed.
      if (options.foo) {
        toggles.use("foo")
      }
    }
  }
}

In the above example, if the foo option of MySausPlugin is falsy, the callSomeFunction line is removed at build time.

Ideally, plugins would use namespaces in their toggle IDs:

// @toggle my-saus-plugin.foo
callSomeFunction(...args)
@aleclarson aleclarson added roadmap proposal An idea not set in stone labels Jul 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal An idea not set in stone roadmap
Projects
None yet
Development

No branches or pull requests

1 participant