|
| 1 | +import { createRequire } from "node:module"; |
1 | 2 | import solid from "vite-plugin-solid"; |
2 | 3 | import { defineConfig } from "vitest/config"; |
3 | 4 | import { playwright } from "@vitest/browser-playwright"; |
4 | 5 |
|
| 6 | +const require = createRequire(import.meta.url); |
| 7 | + |
5 | 8 | export default defineConfig({ |
6 | 9 | plugins: [solid()], |
| 10 | + resolve: { |
| 11 | + alias: { |
| 12 | + "solid-js/web": "@solidjs/web", |
| 13 | + "solid-js/store": "solid-js", |
| 14 | + }, |
| 15 | + conditions: ["solid", "development", "browser"], |
| 16 | + }, |
| 17 | + optimizeDeps: { |
| 18 | + include: ["@solidjs/testing-library"], |
| 19 | + esbuildOptions: { |
| 20 | + plugins: [ |
| 21 | + { |
| 22 | + name: "solid-compat", |
| 23 | + setup(build) { |
| 24 | + // Let Vite resolve @solidjs/web at runtime with proper conditions |
| 25 | + build.onResolve({ filter: /^solid-js\/web$/ }, () => ({ |
| 26 | + path: "@solidjs/web", |
| 27 | + external: true, |
| 28 | + })); |
| 29 | + build.onResolve({ filter: /^solid-js\/store$/ }, () => ({ |
| 30 | + path: require.resolve("solid-js"), |
| 31 | + })); |
| 32 | + // Shim onMount/onError removed in Solid v2 for @solidjs/testing-library compat |
| 33 | + build.onResolve({ filter: /^solid-js$/ }, (args) => { |
| 34 | + if (args.importer?.includes("@solidjs/testing-library")) { |
| 35 | + return { path: args.path, namespace: "solid-compat" }; |
| 36 | + } |
| 37 | + }); |
| 38 | + build.onLoad({ filter: /.*/, namespace: "solid-compat" }, () => ({ |
| 39 | + contents: ` |
| 40 | + export * from ${JSON.stringify(require.resolve("solid-js"))}; |
| 41 | + export function onMount(fn) { queueMicrotask(fn); } |
| 42 | + export function onError() {} |
| 43 | + `, |
| 44 | + resolveDir: ".", |
| 45 | + })); |
| 46 | + }, |
| 47 | + }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + }, |
7 | 51 | test: { |
8 | 52 | mockReset: true, |
9 | 53 | globals: true, |
|
0 commit comments