alloc / alloc/saus

[RFC] Option-driven tree-shaking toggles

未關閉
#74 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
proposal roadmap
主要語言
TypeScript
星號
38
分支
1
PR 合併指標
30 天內沒有已合併 PR

描述

## 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:

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

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

```ts
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:

```ts
// @toggle my-saus-plugin.foo
callSomeFunction(...args)
```

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。