mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +00:00
fix(nitro): support ~/@ aliases and explicitly externalize buildDir
This commit is contained in:
parent
8aae9ef7b2
commit
f98be4bfed
@ -198,6 +198,10 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
|
|||||||
'#nitro-renderer': require.resolve(resolve(nitroContext._internal.runtimeDir, 'app', renderer)),
|
'#nitro-renderer': require.resolve(resolve(nitroContext._internal.runtimeDir, 'app', renderer)),
|
||||||
'#nitro-vue-renderer': vue2ServerRenderer,
|
'#nitro-vue-renderer': vue2ServerRenderer,
|
||||||
'#build': nitroContext._nuxt.buildDir,
|
'#build': nitroContext._nuxt.buildDir,
|
||||||
|
'~': nitroContext._nuxt.srcDir,
|
||||||
|
'@/': nitroContext._nuxt.srcDir,
|
||||||
|
'~~': nitroContext._nuxt.rootDir,
|
||||||
|
'@@/': nitroContext._nuxt.rootDir,
|
||||||
...env.alias
|
...env.alias
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
@ -214,21 +218,22 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
|
|||||||
rollupConfig.plugins.push(externals(defu(nitroContext.externals as any, {
|
rollupConfig.plugins.push(externals(defu(nitroContext.externals as any, {
|
||||||
outDir: nitroContext.output.serverDir,
|
outDir: nitroContext.output.serverDir,
|
||||||
moduleDirectories,
|
moduleDirectories,
|
||||||
ignore: [
|
external: [
|
||||||
|
...(nitroContext._nuxt.dev ? [nitroContext._nuxt.buildDir] : [])
|
||||||
|
],
|
||||||
|
inline: [
|
||||||
|
'#',
|
||||||
|
'~',
|
||||||
|
'@/',
|
||||||
|
'~~',
|
||||||
|
'@@/',
|
||||||
|
'virtual:',
|
||||||
nitroContext._internal.runtimeDir,
|
nitroContext._internal.runtimeDir,
|
||||||
...((!nitroContext._nuxt.dev && [
|
|
||||||
// prod
|
|
||||||
nitroContext._nuxt.srcDir,
|
nitroContext._nuxt.srcDir,
|
||||||
nitroContext._nuxt.rootDir,
|
nitroContext._nuxt.rootDir,
|
||||||
nitroContext._nuxt.buildDir,
|
|
||||||
'vue',
|
|
||||||
'@vue/',
|
|
||||||
'@nuxt/',
|
|
||||||
'#',
|
|
||||||
'virtual:'
|
|
||||||
]) || []),
|
|
||||||
nitroContext._nuxt.serverDir,
|
nitroContext._nuxt.serverDir,
|
||||||
...nitroContext.middleware.map(m => m.handle)
|
...nitroContext.middleware.map(m => m.handle),
|
||||||
|
...(nitroContext._nuxt.dev ? [] : ['vue', '@vue/', '@nuxt/'])
|
||||||
],
|
],
|
||||||
traceOptions: {
|
traceOptions: {
|
||||||
base: '/',
|
base: '/',
|
||||||
|
@ -4,7 +4,8 @@ import { nodeFileTrace, NodeFileTraceOptions } from '@vercel/nft'
|
|||||||
import type { Plugin } from 'rollup'
|
import type { Plugin } from 'rollup'
|
||||||
|
|
||||||
export interface NodeExternalsOptions {
|
export interface NodeExternalsOptions {
|
||||||
ignore?: string[]
|
inline?: string[]
|
||||||
|
external?: string[]
|
||||||
outDir?: string
|
outDir?: string
|
||||||
trace?: boolean
|
trace?: boolean
|
||||||
traceOptions?: NodeFileTraceOptions
|
traceOptions?: NodeFileTraceOptions
|
||||||
@ -25,16 +26,18 @@ export function externals (opts: NodeExternalsOptions): Plugin {
|
|||||||
// Normalize from node_modules
|
// Normalize from node_modules
|
||||||
const _id = id.split('node_modules/').pop()
|
const _id = id.split('node_modules/').pop()
|
||||||
|
|
||||||
|
// Skip checks if is an explicit external
|
||||||
|
if (!opts.external.find(i => _id.startsWith(i) || id.startsWith(i))) {
|
||||||
// Resolve relative paths and exceptions
|
// Resolve relative paths and exceptions
|
||||||
// Ensure to take absolute and relative id
|
// Ensure to take absolute and relative id
|
||||||
if (_id.startsWith('.') || opts.ignore.find(i => _id.startsWith(i) || id.startsWith(i))) {
|
if (_id.startsWith('.') || opts.inline.find(i => _id.startsWith(i) || id.startsWith(i))) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bundle ts
|
// Bundle ts
|
||||||
if (_id.endsWith('.ts')) {
|
if (_id.endsWith('.ts')) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Try to resolve for nft
|
// Try to resolve for nft
|
||||||
if (opts.trace !== false) {
|
if (opts.trace !== false) {
|
||||||
|
Loading…
Reference in New Issue
Block a user