Add experimental outputFileTracingIgnores config (#43103)

This allows filtering out known traces that should be ignored even if
`node-file-trace` detects them as being potentially used.

x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1668761350086149)


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
This commit is contained in:
JJ Kasper 2022-11-18 14:35:28 -08:00 committed by GitHub
parent 24867fd785
commit 70c6f15522
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 7 deletions

View file

@ -1993,13 +1993,15 @@ export default async function getBaseWebpackConfig(
config.outputFileTracing &&
(isNodeServer || isEdgeServer) &&
!dev &&
new (require('./webpack/plugins/next-trace-entrypoints-plugin').TraceEntryPointsPlugin)(
new (require('./webpack/plugins/next-trace-entrypoints-plugin')
.TraceEntryPointsPlugin as typeof import('./webpack/plugins/next-trace-entrypoints-plugin').TraceEntryPointsPlugin)(
{
appDir: dir,
esmExternals: config.experimental.esmExternals,
outputFileTracingRoot: config.experimental.outputFileTracingRoot,
appDirEnabled: hasAppDir,
turbotrace: config.experimental.turbotrace,
traceIgnores: config.experimental.outputFileTracingIgnores || [],
}
),
// Moment.js is an extremely popular library that bundles large locale files

View file

@ -92,7 +92,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
private appDirEnabled?: boolean
private tracingRoot: string
private entryTraces: Map<string, Set<string>>
private excludeFiles: string[]
private traceIgnores: string[]
private esmExternals?: NextConfigComplete['experimental']['esmExternals']
private turbotrace?: NextConfigComplete['experimental']['turbotrace']
private chunksToTrace: string[] = []
@ -102,14 +102,14 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
constructor({
appDir,
appDirEnabled,
excludeFiles,
traceIgnores,
esmExternals,
outputFileTracingRoot,
turbotrace,
}: {
appDir: string
appDirEnabled?: boolean
excludeFiles?: string[]
traceIgnores?: string[]
outputFileTracingRoot?: string
esmExternals?: NextConfigComplete['experimental']['esmExternals']
turbotrace?: NextConfigComplete['experimental']['turbotrace']
@ -118,7 +118,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
this.entryTraces = new Map()
this.esmExternals = esmExternals
this.appDirEnabled = appDirEnabled
this.excludeFiles = excludeFiles || []
this.traceIgnores = traceIgnores || []
this.tracingRoot = outputFileTracingRoot || appDir
this.turbotrace = turbotrace
}
@ -174,7 +174,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
return
}
}
const ignores = [...TRACE_IGNORES, ...this.excludeFiles]
const ignores = [...TRACE_IGNORES, ...this.traceIgnores]
const ignoreFn = (path: string) => {
return isMatch(path, ignores, { contains: true, dot: true })
@ -463,7 +463,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
let reasons: NodeFileTraceReasons
const ignores = [
...TRACE_IGNORES,
...this.excludeFiles,
...this.traceIgnores,
'**/node_modules/**',
]
const ignoreFn = (path: string) => {

View file

@ -335,6 +335,9 @@ const configSchema = {
minLength: 1,
type: 'string',
},
outputFileTracingIgnores: {
type: 'array',
},
pageEnv: {
type: 'boolean',
},

View file

@ -121,6 +121,7 @@ export interface ExperimentalConfig {
fullySpecified?: boolean
urlImports?: NonNullable<webpack.Configuration['experiments']>['buildHttp']
outputFileTracingRoot?: string
outputFileTracingIgnores?: string[]
modularizeImports?: Record<
string,
{