Files
vue-tui/packages/vite/test/fixtures/cjs-config/vite.config.ts
T
Yunfei He e5015b0a80 fix(vite): resolve @vue-tui/vite from CommonJS Vite configs (#243)
* fix(vite): resolve @vue-tui/vite from CommonJS Vite configs

When a consumer project is CommonJS — package.json "type": "commonjs", or
no "type" field at all (Node defaults to CommonJS) — Vite loads vite.config.ts
as CommonJS and resolves its imports under the `require` condition.
@vue-tui/vite's exports used an `import`-only conditions object with no
fallback, so nothing matched under `require` and Vite threw:

    [plugin externalize-deps] Failed to resolve "@vue-tui/vite".
    This package is ESM only but it was tried to load by `require`.

Switch the export to a bare string (plus "./package.json"), matching the
other @vue-tui/* packages and @vitejs/plugin-vue. A string export is
condition-agnostic, so it resolves under both `import` and `require`; Node
then loads the ESM file via require(ESM), which every supported Node
(>=22.18) provides. No CommonJS build is added — this mirrors how the Vite
plugin ecosystem ships today (all ESM-only).

Add a regression test (test/cjs-config.test.ts): a `type: commonjs` fixture
whose vite.config.ts imports @vue-tui/vite by name, loaded through the real
config loader via resolveConfig(). It fails with the exact #238 error on the
old exports and passes with this change.

* chore(lint): exclude test fixtures from linting

Test fixtures are test INPUTS, not shipped source, and some are deliberately
broken: the overlay / full-reload dev-server tests transiently overwrite a
fixture's app.vue with a syntax error (to exercise the error overlay / failed
HMR), then restore it. Because `vp run ci` runs lint concurrently with those
tests, a linter that read a fixture inside that broken window failed with a
spurious "Unexpected token" — a flaky race whose surfacing depended on test
timing. Add lint.ignorePatterns ["**/test/fixtures/**"] to remove the race
(and the wasted lint work on test data).
2026-07-05 18:30:31 +08:00

12 lines
527 B
TypeScript

// Fixture for the #238 regression test (test/cjs-config.test.ts).
//
// The sibling package.json declares `type: commonjs`, so Vite bundles+loads THIS config as
// CommonJS and resolves its imports under the `require` condition. Importing @vue-tui/vite BY
// NAME exercises the published package's exports map: if it isn't resolvable under `require`,
// config loading throws "This package is ESM only but it was tried to load by `require`".
import { vueTui } from "@vue-tui/vite";
export default {
plugins: [vueTui()],
};