mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +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 { pkgDir } from '../dirs'
|
||||||
|
|
||||||
import { dynamicRequire } from './plugins/dynamic-require'
|
import { dynamicRequire } from './plugins/dynamic-require'
|
||||||
import { externals } from './plugins/externals'
|
import { externals, NodeExternalsOptions } from './plugins/externals'
|
||||||
import { timing } from './plugins/timing'
|
import { timing } from './plugins/timing'
|
||||||
// import { autoMock } from './plugins/automock'
|
// import { autoMock } from './plugins/automock'
|
||||||
import { staticAssets, dirnames } from './plugins/static'
|
import { staticAssets, dirnames } from './plugins/static'
|
||||||
@ -249,7 +249,7 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
|
|||||||
|
|
||||||
// Externals Plugin
|
// Externals Plugin
|
||||||
if (nitroContext.externals) {
|
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,
|
outDir: nitroContext.output.serverDir,
|
||||||
moduleDirectories,
|
moduleDirectories,
|
||||||
external: [
|
external: [
|
||||||
@ -266,7 +266,7 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
|
|||||||
nitroContext._nuxt.srcDir,
|
nitroContext._nuxt.srcDir,
|
||||||
nitroContext._nuxt.rootDir,
|
nitroContext._nuxt.rootDir,
|
||||||
nitroContext._nuxt.serverDir,
|
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/'])
|
...(nitroContext._nuxt.dev ? [] : ['vue', '@vue/', '@nuxt/'])
|
||||||
],
|
],
|
||||||
traceOptions: {
|
traceOptions: {
|
||||||
|
@ -10,6 +10,8 @@ export interface NodeExternalsOptions {
|
|||||||
trace?: boolean
|
trace?: boolean
|
||||||
traceOptions?: NodeFileTraceOptions
|
traceOptions?: NodeFileTraceOptions
|
||||||
moduleDirectories?: string[]
|
moduleDirectories?: string[]
|
||||||
|
/** additional packages to include in `.output/server/node_modules` */
|
||||||
|
traceInclude?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function externals (opts: NodeExternalsOptions): Plugin {
|
export function externals (opts: NodeExternalsOptions): Plugin {
|
||||||
@ -67,6 +69,12 @@ export function externals (opts: NodeExternalsOptions): Plugin {
|
|||||||
},
|
},
|
||||||
async buildEnd () {
|
async buildEnd () {
|
||||||
if (opts.trace !== false) {
|
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)
|
const tracedFiles = await nodeFileTrace(Array.from(trackedExternals), opts.traceOptions)
|
||||||
.then(r => Array.from(r.fileList).map(f => resolve(opts.traceOptions.base, f)))
|
.then(r => Array.from(r.fileList).map(f => resolve(opts.traceOptions.base, f)))
|
||||||
.then(r => r.filter(file => file.includes('node_modules')))
|
.then(r => r.filter(file => file.includes('node_modules')))
|
||||||
|
Loading…
Reference in New Issue
Block a user