Ergonomics of vp pack + plugins

Offen
#2,632 1 Kommentar 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
48/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
typescript

Rechercherichtung

Beginne mit dem von vp pack verwendeten Pfad zur Konfigurationsextraktion und dem durch VP_RESOLVING_CONFIG_METADATA gesteuerten Verhalten von lazyPlugins; das Issue enthält eine Reproduktion in vite.config.ts. Führe vp pack mit dem bereitgestellten Plugin aus und verfolge, wie root und pack.plugins an tsdown weitergeleitet werden. Erledigt ist es, wenn Pack-Plugins ausgeführt werden, während sie für vp lint und vp fmt lazy bleiben, und die Zusammensetzung der Root-Plugins geklärt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

pending triage
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:

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:

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:

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
  • Read the Contributing Guidelines.
  • Confirm this request is for Vite+ itself and not for Vite, Vitest, tsdown, Rolldown, or Oxc.
  • Check that there isn't already an issue requesting the same feature.
Vorherrschende Sprache
Rust
Sterne
6.5k
Forks
297
Ø Merge
20 Std. 18 Min.
Gemergte PRs (30 T.)
236

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus voidzero-dev/vite-plus

Alle Issues in voidzero-dev/vite-plus

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.