|
1 | 1 | import { fileURLToPath } from 'node:url' |
2 | 2 | import path from 'pathe' |
3 | | -import { resolveViteId } from '@tanstack/start-plugin-core/utils' |
| 3 | +import { createVirtualModule } from '@tanstack/start-plugin-core' |
4 | 4 | import type { |
5 | 5 | TanStackStartVitePluginCoreOptions, |
6 | 6 | ViteRscForwardSsrResolverStrategy, |
7 | | -} from '@tanstack/start-plugin-core/vite/types' |
8 | | -import type { Plugin, PluginOption, UserConfig } from 'vite' |
| 7 | +} from '@tanstack/start-plugin-core' |
| 8 | +import type { PluginOption, UserConfig } from 'vite' |
9 | 9 |
|
10 | | -type VirtualModuleLoadHandler = (this: { |
11 | | - environment: { name: string } |
12 | | -}) => string |
13 | 10 | const isClientEnvironment = (env: { config: { consumer: string } }) => |
14 | 11 | env.config.consumer === 'client' |
15 | 12 |
|
16 | | -function escapeRegExp(value: string): string { |
17 | | - return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') |
18 | | -} |
19 | | - |
20 | | -function createVirtualModule(opts: { |
21 | | - name: string |
22 | | - moduleId: string |
23 | | - load: VirtualModuleLoadHandler |
24 | | - apply?: Plugin['apply'] |
25 | | - applyToEnvironment?: Plugin['applyToEnvironment'] |
26 | | -}): Plugin { |
27 | | - const resolvedId = resolveViteId(opts.moduleId) |
28 | | - const idFilter = { id: new RegExp(escapeRegExp(opts.moduleId)) } |
29 | | - |
30 | | - return { |
31 | | - name: opts.name, |
32 | | - apply: opts.apply, |
33 | | - applyToEnvironment: opts.applyToEnvironment, |
34 | | - resolveId: { |
35 | | - filter: idFilter, |
36 | | - handler() { |
37 | | - return resolvedId |
38 | | - }, |
39 | | - }, |
40 | | - load: { |
41 | | - filter: idFilter, |
42 | | - handler: opts.load, |
43 | | - }, |
44 | | - } |
45 | | -} |
46 | | - |
47 | 13 | // Virtual module ids used by the React Start RSC runtime. |
48 | 14 | const RSC_HMR_VIRTUAL_ID = 'virtual:tanstack-rsc-hmr' |
49 | 15 | const RSC_RUNTIME_VIRTUAL_ID = 'virtual:tanstack-rsc-runtime' |
|
0 commit comments