Repository navigation
fix: add default analyzeDir value
#1944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { mkdir } from 'node:fs/promises' | ||
| import { dirname, join } from 'pathe' | ||
| import { useNuxt, writeTypes } from '@nuxt/kit' | ||
|
|
||
| export function setupAnalyze (options: { writeTypes: boolean }) { | ||
| const nuxt = useNuxt() | ||
|
|
||
| if (nuxt.options.dev || !nuxt.options.build.analyze) { | ||
| return | ||
| } | ||
|
|
||
| // The Nuxt 2 builder empties `buildDir` before building, which removes `.nuxt/tsconfig.json`. | ||
| // `nuxi build` restores it by calling `writeTypes`, but `nuxi analyze` does not. | ||
| if (options.writeTypes) { | ||
| nuxt.hook('modules:done', async () => { | ||
| await writeTypes(nuxt) | ||
| }) | ||
| } | ||
|
|
||
| nuxt.hook('build:done', async () => { | ||
| await mkdir(nuxt.options.analyzeDir, { recursive: true }) | ||
| }) | ||
|
|
||
| // `webpack-bundle-analyzer` ignores `filename`, so map it to `reportFilename` / `statsFilename` | ||
| nuxt.hook('build:before', () => { | ||
| const analyze = nuxt.options.build.analyze | ||
| if (typeof analyze !== 'object' || !('filename' in analyze) || typeof analyze.filename !== 'string' || 'reportFilename' in analyze) { | ||
| return | ||
| } | ||
| const reportFilename = analyze.filename.includes('{name}') | ||
| ? analyze.filename.replace('{name}', 'client') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolve the report name separately for each webpack configuration. With modern mode enabled, this replacement gives both the Apply the mapping per webpack configuration. Keep
|
||
| : join(dirname(analyze.filename), 'client.html') | ||
|
|
||
| Object.assign(analyze, { | ||
| reportFilename, | ||
| statsFilename: reportFilename.replace(/\.html$/, '.json') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve an explicitly configured For Set the derived
|
||
| }) | ||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generate types after Bridge finishes installing its modules.
This callback runs before the
modules:donecallback that installs auto-imports. At this point,#importsand its type references are not registered.writeTypescaptures the generated configuration once, so itsbuilder:preparedcallback restores that incomplete configuration. (raw.githubusercontent.com)Move type generation to
build:before. Module installation will then be complete, andwriteTypescan still register its restoration callback before the builder clearsbuildDir. (raw.githubusercontent.com)