( base: UserConfig['base'] = configDefaults.base, isBuild: boolean, logger: Logger, )
| 2226 | * electron or expects to deploy |
| 2227 | */ |
| 2228 | export function resolveBaseUrl( |
| 2229 | base: UserConfig['base'] = configDefaults.base, |
| 2230 | isBuild: boolean, |
| 2231 | logger: Logger, |
| 2232 | ): string { |
| 2233 | if (base[0] === '.') { |
| 2234 | logger.warn( |
| 2235 | colors.yellow( |
| 2236 | colors.bold( |
| 2237 | `(!) invalid "base" option: "${base}". The value can only be an absolute ` + |
| 2238 | `URL, "./", or an empty string.`, |
| 2239 | ), |
| 2240 | ), |
| 2241 | ) |
| 2242 | return '/' |
| 2243 | } |
| 2244 | |
| 2245 | // external URL flag |
| 2246 | const isExternal = isExternalUrl(base) |
| 2247 | // no leading slash warn |
| 2248 | if (!isExternal && base[0] !== '/') { |
| 2249 | logger.warn( |
| 2250 | colors.yellow( |
| 2251 | colors.bold(`(!) "base" option should start with a slash.`), |
| 2252 | ), |
| 2253 | ) |
| 2254 | } |
| 2255 | |
| 2256 | // parse base when command is serve or base is not External URL |
| 2257 | if (!isBuild || !isExternal) { |
| 2258 | base = new URL(base, 'http://vite.dev').pathname |
| 2259 | // ensure leading slash |
| 2260 | if (base[0] !== '/') { |
| 2261 | base = '/' + base |
| 2262 | } |
| 2263 | } |
| 2264 | |
| 2265 | return base |
| 2266 | } |
| 2267 | |
| 2268 | function decodeBase(base: string): string { |
| 2269 | try { |
no test coverage detected