|
1 | 1 | import fs from 'node:fs' |
2 | 2 | import path from 'node:path' |
3 | | -import { parse as parseUrl, pathToFileURL } from 'node:url' |
| 3 | +import { pathToFileURL } from 'node:url' |
4 | 4 | import { performance } from 'node:perf_hooks' |
5 | 5 | import { createRequire } from 'node:module' |
6 | 6 | import colors from 'picocolors' |
@@ -808,33 +808,34 @@ export function resolveBaseUrl( |
808 | 808 | ) |
809 | 809 | ) |
810 | 810 | ) |
811 | | - base = '/' |
| 811 | + return '/' |
812 | 812 | } |
813 | 813 |
|
814 | | - // external URL |
815 | | - if (isExternalUrl(base)) { |
816 | | - if (!isBuild) { |
817 | | - // get base from full url during dev |
818 | | - const parsed = parseUrl(base) |
819 | | - base = parsed.pathname || '/' |
820 | | - } |
821 | | - } else { |
| 814 | + // external URL flag |
| 815 | + const isExternal = isExternalUrl(base) |
| 816 | + // no leading slash warn |
| 817 | + if (!isExternal && !base.startsWith('/')) { |
| 818 | + logger.warn( |
| 819 | + colors.yellow(colors.bold(`(!) "base" option should start with a slash.`)) |
| 820 | + ) |
| 821 | + } |
| 822 | + // no ending slash warn |
| 823 | + if (!base.endsWith('/')) { |
| 824 | + logger.warn( |
| 825 | + colors.yellow(colors.bold(`(!) "base" option should end with a slash.`)) |
| 826 | + ) |
| 827 | + } |
| 828 | + |
| 829 | + // parse base when command is serve or base is not External URL |
| 830 | + if (!isBuild || !isExternal) { |
| 831 | + base = new URL(base, 'http://vitejs.dev').pathname |
822 | 832 | // ensure leading slash |
823 | 833 | if (!base.startsWith('/')) { |
824 | | - logger.warn( |
825 | | - colors.yellow( |
826 | | - colors.bold(`(!) "base" option should start with a slash.`) |
827 | | - ) |
828 | | - ) |
829 | 834 | base = '/' + base |
830 | 835 | } |
831 | 836 | } |
832 | | - |
833 | 837 | // ensure ending slash |
834 | 838 | if (!base.endsWith('/')) { |
835 | | - logger.warn( |
836 | | - colors.yellow(colors.bold(`(!) "base" option should end with a slash.`)) |
837 | | - ) |
838 | 839 | base += '/' |
839 | 840 | } |
840 | 841 |
|
|
0 commit comments