Skip to content

Commit

Permalink
fix: revert #5601 #6025, don't resolve rollupOptions.input (#6680)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jan 30, 2022
1 parent 5396a70 commit 2a9da2e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 149 deletions.
2 changes: 2 additions & 0 deletions packages/playground/backend-integration/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function BackendIntegrationExample() {
.sync(`${normalizePath(root)}/**/*`, { onlyFiles: true })
.map((filename) => [path.relative(root, filename), filename])

entrypoints.push(['tailwindcss-colors', 'tailwindcss/colors.js'])

return {
build: {
manifest: true,
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ Repository: rollup/plugins
## @vue/compiler-core
License: MIT
By: Evan You
Repository: git+https://github.com/vuejs/core.git
Repository: git+https://github.com/vuejs/vue-next.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -432,7 +432,7 @@ Repository: git+https://github.com/vuejs/core.git
## @vue/compiler-dom
License: MIT
By: Evan You
Repository: git+https://github.com/vuejs/core.git
Repository: git+https://github.com/vuejs/vue-next.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -461,7 +461,7 @@ Repository: git+https://github.com/vuejs/core.git
## @vue/shared
License: MIT
By: Evan You
Repository: git+https://github.com/vuejs/core.git
Repository: git+https://github.com/vuejs/vue-next.git

> The MIT License (MIT)
>
Expand Down
97 changes: 0 additions & 97 deletions packages/vite/src/node/__tests__/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,100 +66,3 @@ describe('resolveLibFilename', () => {
}).toThrow()
})
})

describe('resolveBuildOptions', () => {
test('resolve build.rollupOptions.input', async () => {
const config = await resolveConfig(
{
build: {
rollupOptions: {
input: 'index.html'
}
}
},
'build',
'production'
)

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 () => {
const config = await resolveConfig(
{
build: {
rollupOptions: {
input: ['index.html']
}
}
},
'build',
'production'
)

expect(config.build.rollupOptions.input).toStrictEqual([
resolve('index.html')
])
})

test('resolve index.html', async () => {
const config = await resolveConfig({}, 'build', 'production')

expect(config.build.rollupOptions.input).toBe(resolve('index.html'))
})

test('resolve build.outdir', async () => {
const config = await resolveConfig(
{ build: { outDir: 'outDir' } },
'build',
'production'
)

expect(config.build.outDir).toBe(resolve('outDir'))
})

test('resolve default build.outdir', async () => {
const config = await resolveConfig({}, 'build', 'production')

expect(config.build.outDir).toBe(resolve('dist'))
})

test('resolve build.lib.entry', async () => {
const config = await resolveConfig(
{ build: { lib: { entry: 'index.html' } } },
'build',
'production'
)

expect(config.build.rollupOptions.input).toBe(resolve('index.html'))
})

test('resolve build.ssr', async () => {
const config = await resolveConfig(
{ build: { ssr: 'ssr.ts' } },
'build',
'production'
)

expect(config.build.rollupOptions.input).toBe(resolve('ssr.ts'))
})
})
62 changes: 18 additions & 44 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,7 @@ export type ResolvedBuildOptions = Required<
>
>

export function resolveBuildOptions(
root: string,
raw?: BuildOptions,
isBuild?: boolean
): ResolvedBuildOptions {
export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions {
const resolved: ResolvedBuildOptions = {
target: 'modules',
polyfillModulePreload: true,
Expand Down Expand Up @@ -276,43 +272,6 @@ export function resolveBuildOptions(
}
}

const resolve = (p: string) =>
p.startsWith('\0') ? p : path.resolve(root, p)

resolved.outDir = resolve(resolved.outDir)

let input

if (raw?.rollupOptions?.input) {
input = Array.isArray(raw.rollupOptions.input)
? raw.rollupOptions.input.map((input) => resolve(input))
: typeof raw.rollupOptions.input === 'object'
? Object.fromEntries(
Object.entries(raw.rollupOptions.input).map(([key, value]) => [
key,
resolve(value)
])
)
: resolve(raw.rollupOptions.input)
} 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')) {
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
Expand Down Expand Up @@ -407,8 +366,6 @@ async function doBuild(
): Promise<RollupOutput | RollupOutput[] | RollupWatcher> {
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

Expand All @@ -420,6 +377,22 @@ async function doBuild(
)
)

const resolve = (p: string) => path.resolve(config.root, p)
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)

// inject ssr arg to plugin load/transform hooks
const plugins = (
ssr ? config.plugins.map((p) => injectSsrFlagToHooks(p)) : config.plugins
Expand Down Expand Up @@ -450,6 +423,7 @@ async function doBuild(

const rollup = require('rollup') as typeof Rollup
const rollupOptions: RollupOptions = {
input,
context: 'globalThis',
preserveEntrySignatures: ssr
? 'allow-extension'
Expand Down
6 changes: 1 addition & 5 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,7 @@ export async function resolveConfig(

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

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

0 comments on commit 2a9da2e

Please sign in to comment.