Skip to content

Commit

Permalink
fix: inconsistent handling of non-ASCII base in resolveConfig and…
Browse files Browse the repository at this point in the history
… dev server (#10247)
  • Loading branch information
PengBoUESTC committed Nov 7, 2022
1 parent c22f50c commit 16e4123
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
@@ -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 @@ -808,33 +808,34 @@ 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 {
// external URL flag
const isExternal = isExternalUrl(base)
// no leading slash warn
if (!isExternal && !base.startsWith('/')) {
logger.warn(
colors.yellow(colors.bold(`(!) "base" option should start with a slash.`))
)
}
// no ending slash warn
if (!base.endsWith('/')) {
logger.warn(
colors.yellow(colors.bold(`(!) "base" option should end with a slash.`))
)
}

// parse base when command is serve or base is not External URL
if (!isBuild || !isExternal) {
base = new URL(base, 'http://vitejs.dev').pathname
// ensure leading slash
if (!base.startsWith('/')) {
logger.warn(
colors.yellow(
colors.bold(`(!) "base" option should start with a slash.`)
)
)
base = '/' + base
}
}

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

Expand Down

0 comments on commit 16e4123

Please sign in to comment.