Skip to content

Commit

Permalink
fix: do not overwrite rollupOptions.input in dev (#6025)
Browse files Browse the repository at this point in the history
  • Loading branch information
ydcjeff authored Dec 13, 2021
1 parent 8735294 commit 6cdf13a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
18 changes: 18 additions & 0 deletions packages/vite/src/node/__tests__/dev.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { resolveConfig } from '..'

describe('resolveBuildOptions in dev', () => {
test('build.rollupOptions should not have input in lib', async () => {
const config = await resolveConfig(
{
build: {
lib: {
entry: './index.js'
}
}
},
'serve'
)

expect(config.build.rollupOptions).not.toHaveProperty('input')
})
})
21 changes: 11 additions & 10 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ export type ResolvedBuildOptions = Required<

export function resolveBuildOptions(
root: string,
raw?: BuildOptions
raw?: BuildOptions,
isBuild?: boolean
): ResolvedBuildOptions {
const resolved: ResolvedBuildOptions = {
target: 'modules',
Expand Down Expand Up @@ -291,14 +292,12 @@ export function resolveBuildOptions(
])
)
: resolve(raw.rollupOptions.input)
} else {
input = resolve(
raw?.lib
? raw.lib.entry
: typeof raw?.ssr === 'string'
? raw.ssr
: 'index.html'
)
} else if (raw?.lib && isBuild) {
input = resolve(raw.lib.entry)
} else if (typeof raw?.ssr === 'string') {
input = resolve(raw.ssr)
} else if (isBuild) {
input = resolve('index.html')
}

if (!!raw?.ssr && typeof input === 'string' && input.endsWith('.html')) {
Expand All @@ -308,7 +307,9 @@ export function resolveBuildOptions(
)
}

resolved.rollupOptions.input = input
if (input) {
resolved.rollupOptions.input = input
}

// handle special build targets
if (resolved.target === 'modules') {
Expand Down
6 changes: 5 additions & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ export async function resolveConfig(

// resolve public base url
const BASE_URL = resolveBaseUrl(config.base, command === 'build', logger)
const resolvedBuildOptions = resolveBuildOptions(resolvedRoot, config.build)
const resolvedBuildOptions = resolveBuildOptions(
resolvedRoot,
config.build,
command === 'build'
)

// resolve cache directory
const pkgPath = lookupFile(
Expand Down

0 comments on commit 6cdf13a

Please sign in to comment.