voidzero-dev / voidzero-dev/vite-plus

Ergonomics of vp pack + plugins

オープン
#2,632 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

pending triage
主要言語
Rust
スター
5.8k
フォーク
262
平均マージ
23時間 18分
マージ済み PR(30日)
139

説明

### Description

Configuring plugins for library packaging via `vp pack` has confusing ergonomics and a potential bug when using `lazyPlugins`:

1. **Root `plugins` are ignored by `vp pack`**: In a library project using `vite.config.ts`, plugins configured at the root (`plugins: [...]`) are not forwarded to `tsdown` during `vp pack`. Users must define them redundantly under `pack.plugins`.
2. **`lazyPlugins` fails silently inside `pack.plugins`**: If a user attempts to wrap `pack.plugins` in `lazyPlugins(() => [...])` to avoid running plugin factories during `vp lint` or `vp fmt`, the plugins never execute during `vp pack`.

### Root Cause

When `vp pack` extracts the `tsdown` config from `vite.config.ts`, `VP_RESOLVING_CONFIG_METADATA` is set to `"1"`.

Inside `lazyPlugins`:
```js
function lazyPlugins(cb) {
if (process.env["VP_RESOLVING_CONFIG_METADATA"] === "1") return;
const result = cb();
return result;
}
```
Because the metadata environment marker is active during config extraction for vp pack, lazyPlugins returns undefined. Consequently, tsdown runs with no plugins.

Reproduction

In vite.config.ts:
```ts
import { defineConfig, lazyPlugins } from 'vite-plus';

function myPlugin() {
return {
name: 'test-plugin',
buildStart() {
console.log('--- PLUGIN EXECUTED ---');
},
};
}

export default defineConfig({
pack: {
entry: ['src/index.ts'],
// ❌ Fails: '--- PLUGIN EXECUTED ---' is never printed
plugins: lazyPlugins(() => [myPlugin()]),

// ⚠️ Works, but runs eagerly during `vp lint` / `vp fmt`:
// plugins: [myPlugin()],
},
// ❌ Ignored by `vp pack`:
// plugins: [myPlugin()],
});
```

Run:
```bash
vp pack
```

### Suggested solution

1. `lazyPlugins` should evaluate when resolving the build pipeline for `vp pack`, so plugins can be lazily loaded without executing during `vp check` / `vp fmt` / `vp lint`.
2. Ideally, plugins defined at the root (`plugins: [...]`) should either auto merge with `pack.plugins` by default when building libraries, or vite-plus should provide clear ergonomics/typing on how root Vite plugins vs. pack plugins compose. It's frankly confusing having two separate places to specify the plugin arrays.

### Alternative

_No response_

### Additional context

_No response_

### Validations

- [x] Read the [Contributing Guidelines](https://github.com/voidzero-dev/vite-plus/blob/main/CONTRIBUTING.md).
- [x] Confirm this request is for Vite+ itself and not for Vite, Vitest, tsdown, Rolldown, or Oxc.
- [x] Check that there isn't already an issue requesting the same feature.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

`vp pack` が使用する設定抽出の経路と、`VP_RESOLVING_CONFIG_METADATA` によって制御される `lazyPlugins` の動作から着手します。issue には `vite.config.ts` での再現が用意されています。提供された plugin を使って `vp pack` を実行し、root と `pack.plugins` がどのように tsdown に渡されるかを追跡します。完了条件は、pack plugins が実行され、`vp lint` と `vp fmt` では lazy のままであり、root-plugin の構成が明確になることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
build-system, tooling
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。