From 627b7b6f71222e3295b997278afeed135064a9d1 Mon Sep 17 00:00:00 2001 From: sibbng Date: Tue, 9 Nov 2021 19:40:18 +0300 Subject: [PATCH 01/11] fix: resolve `rollupOptions.input` paths --- packages/vite/src/node/build.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index b9ccf666b53550..8629db155cce8d 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -374,6 +374,14 @@ async function doBuild( ) const resolve = (p: string) => path.resolve(config.root, p) + + if (Array.isArray(options.rollupOptions?.input)) { + options.rollupOptions.input = options.rollupOptions.input.map(input => resolve(input)) + } + else if (typeof options.rollupOptions?.input === 'string') { + options.rollupOptions.input = resolve(options.rollupOptions.input) + } + const input = libOptions ? resolve(libOptions.entry) : typeof options.ssr === 'string' From d055e40e07f2ccc0fc6768a97e83cbc30fdcf137 Mon Sep 17 00:00:00 2001 From: sibbng Date: Wed, 10 Nov 2021 02:40:08 +0300 Subject: [PATCH 02/11] test: add build resolve tests --- .../vite/src/node/__tests__/build.spec.ts | 65 ++++++++++++++++++- .../node/__tests__/packages/name/index.html | 0 .../src/node/__tests__/packages/name/ssr.ts | 0 packages/vite/src/node/build.ts | 60 ++++++++++------- 4 files changed, 101 insertions(+), 24 deletions(-) create mode 100644 packages/vite/src/node/__tests__/packages/name/index.html create mode 100644 packages/vite/src/node/__tests__/packages/name/ssr.ts diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts index b3ef37e64fd28e..90c25466fabe1b 100644 --- a/packages/vite/src/node/__tests__/build.spec.ts +++ b/packages/vite/src/node/__tests__/build.spec.ts @@ -1,5 +1,6 @@ -import { resolveLibFilename } from '../build' +import { resolveLibFilename, resolvePaths } from '../build' import { resolve } from 'path' +import { resolveConfig } from '..' describe('resolveLibFilename', () => { test('custom filename function', () => { @@ -65,3 +66,65 @@ describe('resolveLibFilename', () => { }).toThrow() }) }) + +describe('resolvePaths', () => { + test('resolve build.rollupOptions.input', async () => { + const config = await resolveConfig({ + build: { + rollupOptions: { + input: 'packages/noname/index.html' + } + } + }, 'build', 'production') + const { input } = resolvePaths(config, config.build) + + expect(input).toBe(resolve('packages/noname/index.html')) + }) + + test('resolve build.rollupOptions.input[]', async () => { + const config = await resolveConfig({ + root: 'packages/noname', + build: { + rollupOptions: { + input: ['index.html'] + } + } + }, 'build', 'production') + const { input } = resolvePaths(config, config.build) + + const resolved = resolve('packages/noname/index.html') + + expect(input).toBe(resolved) + expect(config.build.rollupOptions.input[0]).toBe(resolved) + }) + + test('resolve index.html', async () => { + const config = await resolveConfig({ + root: 'packages/noname', + }, 'build', 'production') + const { input } = resolvePaths(config, config.build) + + expect(input).toBe(resolve('packages/noname/index.html')) + }) + + test('resolve build.outdir', async () => { + const config = await resolveConfig({ build: { outDir: 'packages/noname' } }, 'build', 'production') + const { outDir } = resolvePaths(config, config.build) + + expect(outDir).toBe(resolve('packages/noname')) + }) + + test('resolve build.lib.entry', async () => { + const config = await resolveConfig({ build: { lib: { entry: 'packages/noname/index.html' } } }, 'build', 'production') + const { input } = resolvePaths(config, config.build) + + expect(input).toBe(resolve('packages/noname/index.html')) + }) + + test('resolve build.ssr', async () => { + const config = await resolveConfig({ build: { ssr: 'packages/noname/ssr.ts' } }, 'build', 'production') + const { input } = resolvePaths(config, config.build) + + expect(input).toBe(resolve('packages/noname/ssr.ts')) + }) +}) diff --git a/packages/vite/src/node/__tests__/packages/name/index.html b/packages/vite/src/node/__tests__/packages/name/index.html new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/packages/vite/src/node/__tests__/packages/name/ssr.ts b/packages/vite/src/node/__tests__/packages/name/ssr.ts new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 8629db155cce8d..28d59dc1b83b80 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -329,6 +329,42 @@ export function resolveBuildPlugins(config: ResolvedConfig): { } } +export function resolvePaths(config: ResolvedConfig, options: ResolvedConfig["build"]) { + const rollupOptions = options.rollupOptions + const libOptions = options.lib + const ssr = !!options.ssr + + const resolve = (p: string) => path.resolve(config.root, p) + + rollupOptions.input = Array.isArray(rollupOptions?.input) + ? rollupOptions.input.map(input => resolve(input)) + : typeof rollupOptions?.input === 'string' + ? resolve(rollupOptions.input) + : undefined + + const input = resolve( + libOptions + ? libOptions.entry + : typeof options.ssr === 'string' + ? options.ssr + : typeof rollupOptions?.input === 'string' + ? rollupOptions.input + : 'index.html' + ) + + if (ssr && typeof input === 'string' && input.endsWith('.html')) { + throw new Error( + `rollupOptions.input should not be an html file when building for SSR. ` + + `Please specify a dedicated SSR entry.` + ) + } + + return { + input: resolve(input), + outDir: resolve(options.outDir) + } +} + /** * Track parallel build calls and only stop the esbuild service when all * builds are done. (#1098) @@ -373,29 +409,7 @@ async function doBuild( ) ) - const resolve = (p: string) => path.resolve(config.root, p) - - if (Array.isArray(options.rollupOptions?.input)) { - options.rollupOptions.input = options.rollupOptions.input.map(input => resolve(input)) - } - else if (typeof options.rollupOptions?.input === 'string') { - options.rollupOptions.input = resolve(options.rollupOptions.input) - } - - const input = libOptions - ? resolve(libOptions.entry) - : typeof options.ssr === 'string' - ? resolve(options.ssr) - : options.rollupOptions?.input || resolve('index.html') - - if (ssr && typeof input === 'string' && input.endsWith('.html')) { - throw new Error( - `rollupOptions.input should not be an html file when building for SSR. ` + - `Please specify a dedicated SSR entry.` - ) - } - - const outDir = resolve(options.outDir) + const { input, outDir } = resolvePaths(config, options) // inject ssr arg to plugin load/transform hooks const plugins = ( From dde3b12652dafd866ce3b06b5e398c742293b2c0 Mon Sep 17 00:00:00 2001 From: sibbng Date: Wed, 10 Nov 2021 03:23:14 +0300 Subject: [PATCH 03/11] test: fix tests --- .../vite/src/node/__tests__/build.spec.ts | 4 +-- packages/vite/src/node/build.ts | 25 +++++++------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts index 90c25466fabe1b..7f5be313cc0786 100644 --- a/packages/vite/src/node/__tests__/build.spec.ts +++ b/packages/vite/src/node/__tests__/build.spec.ts @@ -94,8 +94,8 @@ describe('resolvePaths', () => { const resolved = resolve('packages/noname/index.html') - expect(input).toBe(resolved) - expect(config.build.rollupOptions.input[0]).toBe(resolved) + expect(input).toStrictEqual([resolved]) + expect(config.build.rollupOptions.input).toStrictEqual([resolved]) }) test('resolve index.html', async () => { diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 28d59dc1b83b80..70f240e369fc2e 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -336,21 +336,14 @@ export function resolvePaths(config: ResolvedConfig, options: ResolvedConfig["bu const resolve = (p: string) => path.resolve(config.root, p) - rollupOptions.input = Array.isArray(rollupOptions?.input) - ? rollupOptions.input.map(input => resolve(input)) - : typeof rollupOptions?.input === 'string' - ? resolve(rollupOptions.input) - : undefined - - const input = resolve( - libOptions - ? libOptions.entry - : typeof options.ssr === 'string' - ? options.ssr - : typeof rollupOptions?.input === 'string' - ? rollupOptions.input - : 'index.html' - ) + if (Array.isArray(rollupOptions?.input)) + rollupOptions.input = rollupOptions.input.map(input => resolve(input)) + + const input = libOptions + ? libOptions.entry + : typeof options.ssr === 'string' + ? options.ssr + : rollupOptions?.input || 'index.html' if (ssr && typeof input === 'string' && input.endsWith('.html')) { throw new Error( @@ -360,7 +353,7 @@ export function resolvePaths(config: ResolvedConfig, options: ResolvedConfig["bu } return { - input: resolve(input), + input: typeof input === 'string' ? resolve(input) : input, outDir: resolve(options.outDir) } } From 2faef4d1426a89c21e6cdcf23b0c39098257a40b Mon Sep 17 00:00:00 2001 From: sibbng Date: Wed, 10 Nov 2021 13:39:11 +0300 Subject: [PATCH 04/11] test: cleanup --- .../vite/src/node/__tests__/build.spec.ts | 32 +++++++++++-------- .../node/__tests__/packages/name/index.html | 0 .../src/node/__tests__/packages/name/ssr.ts | 0 3 files changed, 18 insertions(+), 14 deletions(-) delete mode 100644 packages/vite/src/node/__tests__/packages/name/index.html delete mode 100644 packages/vite/src/node/__tests__/packages/name/ssr.ts diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts index 7f5be313cc0786..45ae651bd536dd 100644 --- a/packages/vite/src/node/__tests__/build.spec.ts +++ b/packages/vite/src/node/__tests__/build.spec.ts @@ -72,18 +72,17 @@ describe('resolvePaths', () => { const config = await resolveConfig({ build: { rollupOptions: { - input: 'packages/noname/index.html' + input: 'index.html' } } }, 'build', 'production') const { input } = resolvePaths(config, config.build) - expect(input).toBe(resolve('packages/noname/index.html')) + expect(input).toBe(resolve('index.html')) }) test('resolve build.rollupOptions.input[]', async () => { const config = await resolveConfig({ - root: 'packages/noname', build: { rollupOptions: { input: ['index.html'] @@ -92,39 +91,44 @@ describe('resolvePaths', () => { }, 'build', 'production') const { input } = resolvePaths(config, config.build) - const resolved = resolve('packages/noname/index.html') + const resolved = resolve('index.html') expect(input).toStrictEqual([resolved]) expect(config.build.rollupOptions.input).toStrictEqual([resolved]) }) test('resolve index.html', async () => { - const config = await resolveConfig({ - root: 'packages/noname', - }, 'build', 'production') + const config = await resolveConfig({}, 'build', 'production') const { input } = resolvePaths(config, config.build) - expect(input).toBe(resolve('packages/noname/index.html')) + expect(input).toBe(resolve('index.html')) }) test('resolve build.outdir', async () => { - const config = await resolveConfig({ build: { outDir: 'packages/noname' } }, 'build', 'production') + const config = await resolveConfig({ build: { outDir: 'outDir' } }, 'build', 'production') + const { outDir } = resolvePaths(config, config.build) + + expect(outDir).toBe(resolve('outDir')) + }) + + test('resolve default build.outdir', async () => { + const config = await resolveConfig({}, 'build', 'production') const { outDir } = resolvePaths(config, config.build) - expect(outDir).toBe(resolve('packages/noname')) + expect(outDir).toBe(resolve('dist')) }) test('resolve build.lib.entry', async () => { - const config = await resolveConfig({ build: { lib: { entry: 'packages/noname/index.html' } } }, 'build', 'production') + const config = await resolveConfig({ build: { lib: { entry: 'index.html' } } }, 'build', 'production') const { input } = resolvePaths(config, config.build) - expect(input).toBe(resolve('packages/noname/index.html')) + expect(input).toBe(resolve('index.html')) }) test('resolve build.ssr', async () => { - const config = await resolveConfig({ build: { ssr: 'packages/noname/ssr.ts' } }, 'build', 'production') + const config = await resolveConfig({ build: { ssr: 'ssr.ts' } }, 'build', 'production') const { input } = resolvePaths(config, config.build) - expect(input).toBe(resolve('packages/noname/ssr.ts')) + expect(input).toBe(resolve('ssr.ts')) }) }) diff --git a/packages/vite/src/node/__tests__/packages/name/index.html b/packages/vite/src/node/__tests__/packages/name/index.html deleted file mode 100644 index e69de29bb2d1d6..00000000000000 diff --git a/packages/vite/src/node/__tests__/packages/name/ssr.ts b/packages/vite/src/node/__tests__/packages/name/ssr.ts deleted file mode 100644 index e69de29bb2d1d6..00000000000000 From 57a41def67a14ce9222436daf55f5a575255743a Mon Sep 17 00:00:00 2001 From: sibbng Date: Wed, 10 Nov 2021 15:28:20 +0300 Subject: [PATCH 05/11] refactor: move resolve logic to `resolveBuildOptions` --- .../vite/src/node/__tests__/build.spec.ts | 39 ++++++------ packages/vite/src/node/build.ts | 59 ++++++++----------- packages/vite/src/node/config.ts | 2 +- 3 files changed, 48 insertions(+), 52 deletions(-) diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts index 45ae651bd536dd..b745c38aa44790 100644 --- a/packages/vite/src/node/__tests__/build.spec.ts +++ b/packages/vite/src/node/__tests__/build.spec.ts @@ -1,4 +1,4 @@ -import { resolveLibFilename, resolvePaths } from '../build' +import { resolveLibFilename } from '../build' import { resolve } from 'path' import { resolveConfig } from '..' @@ -76,9 +76,21 @@ describe('resolvePaths', () => { } } }, 'build', 'production') - const { input } = resolvePaths(config, config.build) - expect(input).toBe(resolve('index.html')) + expect(config.build.rollupOptions.input).toBe(resolve('index.html')) + }) + test('resolve build.rollupOptions.input{}', async () => { + const config = await resolveConfig({ + build: { + rollupOptions: { + input: { + index: 'index.html' + } + } + } + }, 'build', 'production') + + expect(config.build.rollupOptions.input['index']).toBe(resolve('index.html')) }) test('resolve build.rollupOptions.input[]', async () => { @@ -89,46 +101,37 @@ describe('resolvePaths', () => { } } }, 'build', 'production') - const { input } = resolvePaths(config, config.build) - - const resolved = resolve('index.html') - expect(input).toStrictEqual([resolved]) - expect(config.build.rollupOptions.input).toStrictEqual([resolved]) + expect(config.build.rollupOptions.input).toStrictEqual([resolve('index.html')]) }) test('resolve index.html', async () => { const config = await resolveConfig({}, 'build', 'production') - const { input } = resolvePaths(config, config.build) - expect(input).toBe(resolve('index.html')) + expect(config.build.rollupOptions.input).toBe(resolve('index.html')) }) test('resolve build.outdir', async () => { const config = await resolveConfig({ build: { outDir: 'outDir' } }, 'build', 'production') - const { outDir } = resolvePaths(config, config.build) - expect(outDir).toBe(resolve('outDir')) + expect(config.build.outDir).toBe(resolve('outDir')) }) test('resolve default build.outdir', async () => { const config = await resolveConfig({}, 'build', 'production') - const { outDir } = resolvePaths(config, config.build) - expect(outDir).toBe(resolve('dist')) + expect(config.build.outDir).toBe(resolve('dist')) }) test('resolve build.lib.entry', async () => { const config = await resolveConfig({ build: { lib: { entry: 'index.html' } } }, 'build', 'production') - const { input } = resolvePaths(config, config.build) - expect(input).toBe(resolve('index.html')) + expect(config.build.rollupOptions.input).toBe(resolve('index.html')) }) test('resolve build.ssr', async () => { const config = await resolveConfig({ build: { ssr: 'ssr.ts' } }, 'build', 'production') - const { input } = resolvePaths(config, config.build) - expect(input).toBe(resolve('ssr.ts')) + expect(config.build.rollupOptions.input).toBe(resolve('ssr.ts')) }) }) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 70f240e369fc2e..47cfd062a7c0bd 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -233,7 +233,7 @@ export type ResolvedBuildOptions = Required< > > -export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions { +export function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedBuildOptions { const resolved: ResolvedBuildOptions = { target: 'modules', polyfillModulePreload: true, @@ -269,6 +269,29 @@ export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions { } } + const resolve = (p: string) => path.resolve(root, p) + + resolved.outDir = resolve(resolved.outDir) + + if (raw?.rollupOptions?.input) { + resolved.rollupOptions.input = Array.isArray(raw.rollupOptions.input) + ? raw.rollupOptions.input.map(input => resolve(input)) + : typeof raw.rollupOptions.input === 'object' + ? Object.keys(raw.rollupOptions.input).map(key => { + // @ts-ignore + raw.rollupOptions.input[key] = resolve(raw.rollupOptions.input[key]) + }) && raw.rollupOptions.input + : resolve(raw.rollupOptions.input) + } else { + resolved.rollupOptions.input = resolve( + raw?.lib + ? raw.lib.entry + : typeof raw?.ssr === 'string' + ? raw.ssr + : 'index.html' + ) + } + // handle special build targets if (resolved.target === 'modules') { // Support browserslist @@ -329,35 +352,6 @@ export function resolveBuildPlugins(config: ResolvedConfig): { } } -export function resolvePaths(config: ResolvedConfig, options: ResolvedConfig["build"]) { - const rollupOptions = options.rollupOptions - const libOptions = options.lib - const ssr = !!options.ssr - - const resolve = (p: string) => path.resolve(config.root, p) - - if (Array.isArray(rollupOptions?.input)) - rollupOptions.input = rollupOptions.input.map(input => resolve(input)) - - const input = libOptions - ? libOptions.entry - : typeof options.ssr === 'string' - ? options.ssr - : rollupOptions?.input || 'index.html' - - if (ssr && typeof input === 'string' && input.endsWith('.html')) { - throw new Error( - `rollupOptions.input should not be an html file when building for SSR. ` + - `Please specify a dedicated SSR entry.` - ) - } - - return { - input: typeof input === 'string' ? resolve(input) : input, - outDir: resolve(options.outDir) - } -} - /** * Track parallel build calls and only stop the esbuild service when all * builds are done. (#1098) @@ -391,6 +385,8 @@ async function doBuild( ): Promise { const config = await resolveConfig(inlineConfig, 'build', 'production') const options = config.build + const input = options.rollupOptions.input + const outDir = options.outDir const ssr = !!options.ssr const libOptions = options.lib @@ -402,8 +398,6 @@ async function doBuild( ) ) - const { input, outDir } = resolvePaths(config, options) - // inject ssr arg to plugin load/transform hooks const plugins = ( ssr ? config.plugins.map((p) => injectSsrFlagToHooks(p)) : config.plugins @@ -436,7 +430,6 @@ async function doBuild( const rollup = require('rollup') as typeof Rollup const rollupOptions: RollupOptions = { - input, context: 'globalThis', preserveEntrySignatures: ssr ? 'allow-extension' diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 51a9ffac7f3bb6..c627fc5c502886 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -364,7 +364,7 @@ export async function resolveConfig( // resolve public base url const BASE_URL = resolveBaseUrl(config.base, command === 'build', logger) - const resolvedBuildOptions = resolveBuildOptions(config.build) + const resolvedBuildOptions = resolveBuildOptions(resolvedRoot, config.build) // resolve cache directory const pkgPath = lookupFile( From 3127219bfa4129538fe5448c86b7e9aa1fe4d9ea Mon Sep 17 00:00:00 2001 From: sibbng Date: Wed, 10 Nov 2021 15:56:45 +0300 Subject: [PATCH 06/11] fix: don't resolve virtual inputs --- packages/plugin-legacy/index.js | 2 +- packages/vite/src/node/build.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/plugin-legacy/index.js b/packages/plugin-legacy/index.js index bfa6ee491bcbf6..2267cd9cf82b42 100644 --- a/packages/plugin-legacy/index.js +++ b/packages/plugin-legacy/index.js @@ -596,7 +596,7 @@ async function buildPolyfillChunk( bundle[polyfillChunk.name] = polyfillChunk } -const polyfillId = 'vite/legacy-polyfills' +const polyfillId = '\0vite/legacy-polyfills' /** * @param {Set} imports diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 47cfd062a7c0bd..3896392e58bdfb 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -269,7 +269,7 @@ export function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedB } } - const resolve = (p: string) => path.resolve(root, p) + const resolve = (p: string) => p.startsWith('\0') ? p : path.resolve(root, p) resolved.outDir = resolve(resolved.outDir) From 60a640e3ba97f66615e382925202bed48e77d8a5 Mon Sep 17 00:00:00 2001 From: sibbng Date: Wed, 10 Nov 2021 16:54:49 +0300 Subject: [PATCH 07/11] fix: don't mutate raw config --- packages/vite/src/node/build.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 3896392e58bdfb..64875787ec4dbe 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -277,10 +277,10 @@ export function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedB resolved.rollupOptions.input = Array.isArray(raw.rollupOptions.input) ? raw.rollupOptions.input.map(input => resolve(input)) : typeof raw.rollupOptions.input === 'object' - ? Object.keys(raw.rollupOptions.input).map(key => { + ? Object.assign( // @ts-ignore - raw.rollupOptions.input[key] = resolve(raw.rollupOptions.input[key]) - }) && raw.rollupOptions.input + ...Object.keys(raw.rollupOptions.input).map(key => ({[key]: resolve(raw.rollupOptions.input[key]) })) + ) : resolve(raw.rollupOptions.input) } else { resolved.rollupOptions.input = resolve( From 66d0373945042d2caf37dbd8da25528bcac28686 Mon Sep 17 00:00:00 2001 From: sibbng Date: Wed, 10 Nov 2021 16:57:00 +0300 Subject: [PATCH 08/11] chore: format --- packages/vite/src/node/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 64875787ec4dbe..f671027c4869a7 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -279,7 +279,7 @@ export function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedB : typeof raw.rollupOptions.input === 'object' ? Object.assign( // @ts-ignore - ...Object.keys(raw.rollupOptions.input).map(key => ({[key]: resolve(raw.rollupOptions.input[key]) })) + ...Object.keys(raw.rollupOptions.input).map(key => ({ [key]: resolve(raw.rollupOptions.input[key]) })) ) : resolve(raw.rollupOptions.input) } else { From f7891f237c3c1e920653fe5d339082a7bc87bcb3 Mon Sep 17 00:00:00 2001 From: sibbng Date: Wed, 10 Nov 2021 17:07:29 +0300 Subject: [PATCH 09/11] chore: bring back error --- packages/vite/src/node/build.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index f671027c4869a7..2128a463305d75 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -292,6 +292,13 @@ export function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedB ) } + if (!!raw?.ssr && typeof resolved.rollupOptions.input === 'string' && resolved.rollupOptions.input.endsWith('.html')) { + throw new Error( + `rollupOptions.input should not be an html file when building for SSR. ` + + `Please specify a dedicated SSR entry.` + ) + } + // handle special build targets if (resolved.target === 'modules') { // Support browserslist From 9d197f8d25939864bd64101d0305045107460607 Mon Sep 17 00:00:00 2001 From: sibbng Date: Wed, 10 Nov 2021 17:13:09 +0300 Subject: [PATCH 10/11] chore: cleanup --- packages/vite/src/node/build.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 2128a463305d75..325ef8a92066fc 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -273,8 +273,10 @@ export function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedB resolved.outDir = resolve(resolved.outDir) + let input + if (raw?.rollupOptions?.input) { - resolved.rollupOptions.input = Array.isArray(raw.rollupOptions.input) + input = Array.isArray(raw.rollupOptions.input) ? raw.rollupOptions.input.map(input => resolve(input)) : typeof raw.rollupOptions.input === 'object' ? Object.assign( @@ -283,7 +285,7 @@ export function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedB ) : resolve(raw.rollupOptions.input) } else { - resolved.rollupOptions.input = resolve( + input = resolve( raw?.lib ? raw.lib.entry : typeof raw?.ssr === 'string' @@ -292,13 +294,16 @@ export function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedB ) } - if (!!raw?.ssr && typeof resolved.rollupOptions.input === 'string' && resolved.rollupOptions.input.endsWith('.html')) { + if (!!raw?.ssr && typeof input === 'string' && input.endsWith('.html')) { throw new Error( `rollupOptions.input should not be an html file when building for SSR. ` + `Please specify a dedicated SSR entry.` ) } + if (input) + resolved.rollupOptions.input = input + // handle special build targets if (resolved.target === 'modules') { // Support browserslist From 3ac0afde83ad1ba307bedc3490bd5df944f22979 Mon Sep 17 00:00:00 2001 From: sibbng Date: Wed, 10 Nov 2021 17:19:50 +0300 Subject: [PATCH 11/11] chore: remove unnecessary if condition --- packages/vite/src/node/build.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 325ef8a92066fc..a374bc9908f353 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -301,8 +301,7 @@ export function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedB ) } - if (input) - resolved.rollupOptions.input = input + resolved.rollupOptions.input = input // handle special build targets if (resolved.target === 'modules') {