mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55: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 && [
|
nitroContext._nuxt.srcDir,
|
||||||
// prod
|
nitroContext._nuxt.rootDir,
|
||||||
nitroContext._nuxt.srcDir,
|
|
||||||
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,15 +26,17 @@ 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()
|
||||||
|
|
||||||
// Resolve relative paths and exceptions
|
// Skip checks if is an explicit external
|
||||||
// Ensure to take absolute and relative id
|
if (!opts.external.find(i => _id.startsWith(i) || id.startsWith(i))) {
|
||||||
if (_id.startsWith('.') || opts.ignore.find(i => _id.startsWith(i) || id.startsWith(i))) {
|
// Resolve relative paths and exceptions
|
||||||
return null
|
// Ensure to take absolute and relative id
|
||||||
}
|
if (_id.startsWith('.') || opts.inline.find(i => _id.startsWith(i) || id.startsWith(i))) {
|
||||||
|
return null
|
||||||
// Bundle ts
|
}
|
||||||
if (_id.endsWith('.ts')) {
|
// Bundle ts
|
||||||
return null
|
if (_id.endsWith('.ts')) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to resolve for nft
|
// Try to resolve for nft
|
||||||
|
Loading…
Reference in New Issue
Block a user