Skip to content

Commit

Permalink
fix: use normalizePath
Browse files Browse the repository at this point in the history
  • Loading branch information
btea committed Aug 23, 2022
1 parent ed06a62 commit d203f89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 2 additions & 4 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,12 @@ async function doBuild(
)

const resolve = (p: string) => path.resolve(config.root, p)
let input = libOptions
const input = libOptions
? resolve(libOptions.entry)
: typeof options.ssr === 'string'
? resolve(options.ssr)
: options.rollupOptions?.input || resolve('index.html')
if (input === 'index.html') {
input = resolve(input)
}

if (ssr && typeof input === 'string' && input.endsWith('.html')) {
throw new Error(
`rollupOptions.input should not be an html file when building for SSR. ` +
Expand Down
13 changes: 9 additions & 4 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import {
isDataUrl,
isExternalUrl,
normalizePath,
processSrcSet,
slash
processSrcSet
} from '../utils'
import type { ResolvedConfig } from '../config'
import { toOutputFilePathInHtml } from '../build'
Expand Down Expand Up @@ -246,7 +245,10 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {

async transform(html, id) {
if (id.endsWith('.html')) {
const relativeUrlPath = slash(path.relative(config.root, id))
const relativeUrlPath = path.posix.relative(
config.root,
normalizePath(id)
)
const publicPath = `/${relativeUrlPath}`
const publicBase = getBaseInHTML(relativeUrlPath, config)

Expand Down Expand Up @@ -620,7 +622,10 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
}

for (const [id, html] of processedHtml) {
const relativeUrlPath = path.posix.relative(config.root, id)
const relativeUrlPath = path.posix.relative(
config.root,
normalizePath(id)
)
const assetsBase = getBaseInHTML(relativeUrlPath, config)
const toOutputFilePath = (
filename: string,
Expand Down

0 comments on commit d203f89

Please sign in to comment.