mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 15:42:09 +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-vue-renderer': vue2ServerRenderer,
|
||||
'#build': nitroContext._nuxt.buildDir,
|
||||
'~': nitroContext._nuxt.srcDir,
|
||||
'@/': nitroContext._nuxt.srcDir,
|
||||
'~~': nitroContext._nuxt.rootDir,
|
||||
'@@/': nitroContext._nuxt.rootDir,
|
||||
...env.alias
|
||||
}
|
||||
}))
|
||||
@ -214,21 +218,22 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
|
||||
rollupConfig.plugins.push(externals(defu(nitroContext.externals as any, {
|
||||
outDir: nitroContext.output.serverDir,
|
||||
moduleDirectories,
|
||||
ignore: [
|
||||
external: [
|
||||
...(nitroContext._nuxt.dev ? [nitroContext._nuxt.buildDir] : [])
|
||||
],
|
||||
inline: [
|
||||
'#',
|
||||
'~',
|
||||
'@/',
|
||||
'~~',
|
||||
'@@/',
|
||||
'virtual:',
|
||||
nitroContext._internal.runtimeDir,
|
||||
...((!nitroContext._nuxt.dev && [
|
||||
// prod
|
||||
nitroContext._nuxt.srcDir,
|
||||
nitroContext._nuxt.rootDir,
|
||||
nitroContext._nuxt.buildDir,
|
||||
'vue',
|
||||
'@vue/',
|
||||
'@nuxt/',
|
||||
'#',
|
||||
'virtual:'
|
||||
]) || []),
|
||||
nitroContext._nuxt.serverDir,
|
||||
...nitroContext.middleware.map(m => m.handle)
|
||||
...nitroContext.middleware.map(m => m.handle),
|
||||
...(nitroContext._nuxt.dev ? [] : ['vue', '@vue/', '@nuxt/'])
|
||||
],
|
||||
traceOptions: {
|
||||
base: '/',
|
||||
|
@ -4,7 +4,8 @@ import { nodeFileTrace, NodeFileTraceOptions } from '@vercel/nft'
|
||||
import type { Plugin } from 'rollup'
|
||||
|
||||
export interface NodeExternalsOptions {
|
||||
ignore?: string[]
|
||||
inline?: string[]
|
||||
external?: string[]
|
||||
outDir?: string
|
||||
trace?: boolean
|
||||
traceOptions?: NodeFileTraceOptions
|
||||
@ -25,16 +26,18 @@ export function externals (opts: NodeExternalsOptions): Plugin {
|
||||
// Normalize from node_modules
|
||||
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
|
||||
// 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
|
||||
}
|
||||
|
||||
// Bundle ts
|
||||
if (_id.endsWith('.ts')) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// Try to resolve for nft
|
||||
if (opts.trace !== false) {
|
||||
|
Loading…
Reference in New Issue
Block a user