mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
feat(nitro): specify packages to copy to .output/server/node_modules
(#2382)
This commit is contained in:
parent
a1a2d2f92b
commit
c8e281e7b6
@ -22,7 +22,7 @@ import { resolvePath } from '../utils'
|
||||
import { pkgDir } from '../dirs'
|
||||
|
||||
import { dynamicRequire } from './plugins/dynamic-require'
|
||||
import { externals } from './plugins/externals'
|
||||
import { externals, NodeExternalsOptions } from './plugins/externals'
|
||||
import { timing } from './plugins/timing'
|
||||
// import { autoMock } from './plugins/automock'
|
||||
import { staticAssets, dirnames } from './plugins/static'
|
||||
@ -249,7 +249,7 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
|
||||
|
||||
// Externals Plugin
|
||||
if (nitroContext.externals) {
|
||||
rollupConfig.plugins.push(externals(defu(nitroContext.externals as any, {
|
||||
rollupConfig.plugins.push(externals(defu(nitroContext.externals as NodeExternalsOptions, {
|
||||
outDir: nitroContext.output.serverDir,
|
||||
moduleDirectories,
|
||||
external: [
|
||||
@ -266,7 +266,7 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
|
||||
nitroContext._nuxt.srcDir,
|
||||
nitroContext._nuxt.rootDir,
|
||||
nitroContext._nuxt.serverDir,
|
||||
...nitroContext.middleware.map(m => m.handle),
|
||||
...nitroContext.middleware.map(m => m.handle).filter(i => typeof i === 'string') as string[],
|
||||
...(nitroContext._nuxt.dev ? [] : ['vue', '@vue/', '@nuxt/'])
|
||||
],
|
||||
traceOptions: {
|
||||
|
@ -10,6 +10,8 @@ export interface NodeExternalsOptions {
|
||||
trace?: boolean
|
||||
traceOptions?: NodeFileTraceOptions
|
||||
moduleDirectories?: string[]
|
||||
/** additional packages to include in `.output/server/node_modules` */
|
||||
traceInclude?: string[]
|
||||
}
|
||||
|
||||
export function externals (opts: NodeExternalsOptions): Plugin {
|
||||
@ -67,6 +69,12 @@ export function externals (opts: NodeExternalsOptions): Plugin {
|
||||
},
|
||||
async buildEnd () {
|
||||
if (opts.trace !== false) {
|
||||
for (const pkgName of opts.traceInclude || []) {
|
||||
const path = await this.resolve(pkgName)
|
||||
if (path?.id) {
|
||||
trackedExternals.add(path.id)
|
||||
}
|
||||
}
|
||||
const tracedFiles = await nodeFileTrace(Array.from(trackedExternals), opts.traceOptions)
|
||||
.then(r => Array.from(r.fileList).map(f => resolve(opts.traceOptions.base, f)))
|
||||
.then(r => r.filter(file => file.includes('node_modules')))
|
||||
|
Loading…
Reference in New Issue
Block a user