(env: Environment | null, id: string)
| 81 | let minify = true |
| 82 | |
| 83 | function createRoot(env: Environment | null, id: string) { |
| 84 | type ResolveFn = (id: string, base: string) => Promise<string | false | undefined> |
| 85 | |
| 86 | let customCssResolver: ResolveFn |
| 87 | let customJsResolver: ResolveFn |
| 88 | |
| 89 | if (!env) { |
| 90 | // Older, pre-environment Vite API |
| 91 | // TODO: Can we drop this?? |
| 92 | let cssResolver = config!.createResolver({ |
| 93 | ...config!.resolve, |
| 94 | extensions: ['.css'], |
| 95 | mainFields: ['style'], |
| 96 | conditions: ['style', 'development|production'], |
| 97 | tryIndex: false, |
| 98 | preferRelative: true, |
| 99 | }) |
| 100 | |
| 101 | let jsResolver = config!.createResolver(config!.resolve) |
| 102 | |
| 103 | customCssResolver = createCustomResolver( |
| 104 | [ |
| 105 | (id, importer) => cssResolver(id, importer, true, isSSR), |
| 106 | (id, importer) => cssResolver(id, importer, false, isSSR), |
| 107 | ], |
| 108 | (path) => path.endsWith('.css'), |
| 109 | ) |
| 110 | customJsResolver = createCustomResolver( |
| 111 | [ |
| 112 | (id, importer) => jsResolver(id, importer, true, isSSR), |
| 113 | (id, importer) => jsResolver(id, importer, false, isSSR), |
| 114 | ], |
| 115 | (path) => !path.endsWith('.css'), |
| 116 | ) |
| 117 | } else { |
| 118 | type ResolveIdFn = ( |
| 119 | environment: Environment, |
| 120 | id: string, |
| 121 | importer?: string, |
| 122 | aliasOnly?: boolean, |
| 123 | ) => Promise<string | undefined> |
| 124 | |
| 125 | // There are cases where Environment API is available, |
| 126 | // but `createResolver` is still overridden (for example astro v5) |
| 127 | // |
| 128 | // Copied as-is from vite, because this function is not a part of public API |
| 129 | // |
| 130 | // TODO: Remove this function and pre-environment code when Vite < 7 is no longer supported |
| 131 | function createBackCompatIdResolver( |
| 132 | config: ResolvedConfig, |
| 133 | options?: Partial<InternalResolveOptions>, |
| 134 | ): ResolveIdFn { |
| 135 | const compatResolve = config.createResolver(options) |
| 136 | let resolve: ResolveIdFn |
| 137 | return async (environment, id, importer, aliasOnly) => { |
| 138 | if (environment.name === 'client' || environment.name === 'ssr') { |
| 139 | return compatResolve(id, importer, aliasOnly, environment.name === 'ssr') |
| 140 | } |
no test coverage detected