fix(nitro): support ~/@ aliases and explicitly externalize buildDir

This commit is contained in:
Pooya Parsa 2021-06-04 22:04:08 +02:00
parent 8aae9ef7b2
commit f98be4bfed
2 changed files with 31 additions and 23 deletions

View File

@ -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.srcDir,
nitroContext._nuxt.rootDir,
nitroContext._nuxt.serverDir,
...nitroContext.middleware.map(m => m.handle)
...nitroContext.middleware.map(m => m.handle),
...(nitroContext._nuxt.dev ? [] : ['vue', '@vue/', '@nuxt/'])
],
traceOptions: {
base: '/',

View File

@ -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,15 +26,17 @@ export function externals (opts: NodeExternalsOptions): Plugin {
// Normalize from node_modules
const _id = id.split('node_modules/').pop()
// 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))) {
return null
}
// Bundle ts
if (_id.endsWith('.ts')) {
return null
// 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.inline.find(i => _id.startsWith(i) || id.startsWith(i))) {
return null
}
// Bundle ts
if (_id.endsWith('.ts')) {
return null
}
}
// Try to resolve for nft