Skip to content

Commit

Permalink
fix: handle when base is an external URL
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jul 25, 2021
1 parent 2c1e229 commit c32c5ac
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
}
return [
`import { updateStyle, removeStyle } from ${JSON.stringify(
path.posix.join(config.base, CLIENT_PUBLIC_PATH)
config.base + CLIENT_PUBLIC_PATH.slice(1)
)}`,
`const id = ${JSON.stringify(id)}`,
`const css = ${JSON.stringify(css)}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function markExplicitImport(url: string) {
*/
export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
const { root, base } = config
const clientPublicPath = path.posix.join(base, CLIENT_PUBLIC_PATH)
const clientPublicPath = base + CLIENT_PUBLIC_PATH.slice(1)

let server: ViteDevServer

Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/server/middlewares/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { Connect } from 'types/connect'
export function baseMiddleware({
config
}: ViteDevServer): Connect.NextHandleFunction {
const base = config.base
let base = config.base
if (/^https?:\/\//.test(base)) {
base = parseUrl(base).pathname!
}

// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
return function viteBaseMiddleware(req, res, next) {
Expand Down

0 comments on commit c32c5ac

Please sign in to comment.