Skip to content

Commit

Permalink
feat(config): add entryRoot option
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed May 7, 2024
1 parent 66f12ab commit 0e6fec5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 6 additions & 3 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ export async function build(
),
)

const resolve = (p: string) => path.resolve(config.root, p)
const entryRoot = config.entryRoot || config.root
const resolve = (p: string) => path.resolve(entryRoot, p)
const input = libOptions
? options.rollupOptions?.input ||
(typeof libOptions.entry === 'string'
Expand Down Expand Up @@ -522,7 +523,7 @@ export async function build(
}
}

const outDir = resolve(options.outDir)
const outDir = path.resolve(config.root, options.outDir)

// inject ssr arg to plugin load/transform hooks
const plugins = (
Expand Down Expand Up @@ -731,7 +732,9 @@ export async function build(
clearLine()
if (startTime) {
config.logger.error(
`${colors.red('x')} Build failed in ${displayTime(Date.now() - startTime)}`,
`${colors.red('x')} Build failed in ${displayTime(
Date.now() - startTime,
)}`,
)
startTime = undefined
}
Expand Down
6 changes: 6 additions & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ export interface UserConfig {
* @default process.cwd()
*/
root?: string
/**
* Entry root directory. Can be an absolute path, or a path relative from the
* project's `root` option. If defined, any `.html` entry files are resolved
* relative to this directory.
*/
entryRoot?: string
/**
* Base public path when served in development or production.
* @default '/'
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export async function _createServer(

const initPublicFilesPromise = initPublicFiles(config)

const { root, server: serverConfig } = config
const { root, entryRoot = root, server: serverConfig } = config
const httpsOptions = await resolveHttpsConfig(config.server.https)
const { middlewareMode } = serverConfig

Expand Down Expand Up @@ -905,7 +905,7 @@ export async function _createServer(
if (config.appType === 'spa' || config.appType === 'mpa') {
middlewares.use(
htmlFallbackMiddleware(
root,
entryRoot,
config.appType === 'spa',
getFsUtils(config),
),
Expand All @@ -919,7 +919,7 @@ export async function _createServer(

if (config.appType === 'spa' || config.appType === 'mpa') {
// transform index.html
middlewares.use(indexHtmlMiddleware(root, server))
middlewares.use(indexHtmlMiddleware(entryRoot, server))

// handle 404s
middlewares.use(notFoundMiddleware())
Expand Down

0 comments on commit 0e6fec5

Please sign in to comment.