Skip to content

Commit

Permalink
[next] use tsconfig.build.json for production build (#76373)
Browse files Browse the repository at this point in the history
### Why?

The types of unit tests and stories were included in the package.
Exclude them by using `tsconfig.declaration.json` when `pnpm run types`
during production build.

| Before | After |
|--------|--------|
| ![CleanShot 2025-02-22 at 18 53
43@2x](https://github.com/user-attachments/assets/4e926395-4c53-4d82-aaf9-e7aa03124294)
| ![CleanShot 2025-02-22 at 19 09
37@2x](https://github.com/user-attachments/assets/9a4d3fbc-f5b8-421e-9cb5-d8d0aa1d7509)
|

Closes NDX-747

---------

Co-authored-by: Sebastian Sebbie Silbermann <sebastian.silbermann@vercel.com>
  • Loading branch information
devjiwonchoi and eps1lon authored Feb 23, 2025
1 parent 58d328a commit 4b23c7b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"release": "taskr release",
"build": "pnpm release",
"prepublishOnly": "cd ../../ && turbo run build",
"types": "tsc --declaration --emitDeclarationOnly --stripInternal --declarationDir dist",
"types": "tsc --project tsconfig.build.json --declaration --emitDeclarationOnly --stripInternal --declarationDir dist",
"typescript": "tsec --noEmit",
"ncc-compiled": "taskr ncc",
"storybook": "storybook dev -p 6006",
Expand Down
4 changes: 2 additions & 2 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2573,14 +2573,14 @@ export async function nextbuildjest(task, opts) {

export async function client(task, opts) {
await task
.source('src/client/**/!(*.test).+(js|ts|tsx|woff2)')
.source('src/client/**/!(*.test|*.stories).+(js|ts|tsx|woff2)')
.swc('client', { dev: opts.dev, interopClientDefaultExport: true })
.target('dist/client')
}

export async function client_esm(task, opts) {
await task
.source('src/client/**/!(*.test).+(js|ts|tsx|woff2)')
.source('src/client/**/!(*.test|*.stories).+(js|ts|tsx|woff2)')
.swc('client', { dev: opts.dev, esm: true })
.target('dist/esm/client')
}
Expand Down
20 changes: 20 additions & 0 deletions packages/next/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",
// Copied from tsconfig.json to not overwrite.
"exclude": [
"dist",
"./*.d.ts",
"future/*.d.ts",
"image-types/global.d.ts",
"compat/*.d.ts",
"legacy/*.d.ts",
"types/compiled.d.ts",
"navigation-types/*.d.ts",
"navigation-types/compat/*.d.ts",
"experimental/**/*.d.ts",
// Don't generate types for internal files.
"./**/*.test.ts",
"./**/*.test.tsx",
"./**/*.stories.tsx"
]
}
2 changes: 2 additions & 0 deletions packages/next/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"target": "ES2018",
"moduleResolution": "node"
},
// When changing `exclude`, also update
// `tsconfig.build.json`.
"exclude": [
"dist",
"./*.d.ts",
Expand Down

0 comments on commit 4b23c7b

Please # to comment.