Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inconsistent handling of non-ASCII base in resolveConfig and dev server #10247

Merged
merged 7 commits into from Nov 7, 2022
40 changes: 19 additions & 21 deletions packages/vite/src/node/config.ts
@@ -1,6 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { parse as parseUrl, pathToFileURL } from 'node:url'
import { pathToFileURL } from 'node:url'
import { performance } from 'node:perf_hooks'
import { createRequire } from 'node:module'
import colors from 'picocolors'
Expand Down Expand Up @@ -812,33 +812,31 @@ export function resolveBaseUrl(
)
)
)
base = '/'
return '/'
}

// external URL
if (isExternalUrl(base)) {
if (!isBuild) {
// get base from full url during dev
const parsed = parseUrl(base)
base = parsed.pathname || '/'
}
} else {
// ensure leading slash
if (!base.startsWith('/')) {
logger.warn(
colors.yellow(
colors.bold(`(!) "base" option should start with a slash.`)
)
)
base = '/' + base
}
// no leading slash warn
if (!base.startsWith('/')) {
logger.warn(
colors.yellow(colors.bold(`(!) "base" option should start with a slash.`))
)
}

// ensure ending slash
// no ending slash warn
if (!base.endsWith('/')) {
logger.warn(
colors.yellow(colors.bold(`(!) "base" option should end with a slash.`))
)
}

if (!isBuild || !isExternalUrl(base)) {
base = new URL(base, 'http://vitejs.dev').pathname
}
// ensure leading slash
if (!base.startsWith('/')) {
base = '/' + base
}
// ensure ending slash
if (!base.endsWith('/')) {
base += '/'
}

Expand Down