-
Notifications
You must be signed in to change notification settings - Fork 28.3k
feat: support next.config.ts #50126
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
feat: support next.config.ts #50126
Conversation
@ijjk Can you review this PR? |
Notifying the following users due to files changed in this PR: @timneutkens, @ijjk, @shuding, @styfle, @huozhi:
This comment was posted based on the notify modifier. |
Could this PR be reviewed? |
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.
This PR is introducing additional dependencies, e.g. jiti and sucrase and causes a divergence between how TypeScript is handled in next.config.ts and the application, these should be the same as otherwise application code will behave differently. I.e. you'll have to run webpack on the next.config.ts with the same configuration as the application code and then run the require on the output bundle.
> Note: port of #57656 ## What? This PR initiated support of `next.config.ts`. Follow ups: - update docs ([x-ref](2ea9b6e)) - update cna ts templates ([x-ref](80e6740)) ## Why? > Next.js provides a TypeScript-first development experience for building your React application. This PR can resolve the two main needs: 1. Import TS files to the config. 2. Conduct a type check directly by importing `type` instead of JSDoc. x-ref: #5318 #35969 #44632 #50121 #50126 ## How? ### Goals - [x] [do not bundle](#57656 (comment)) - [x] [minimum fs operations](#63051 (comment)) - [x] zero restrictions Used `require.extensions` hooks to transpile the imported files on the fly. To reduce I/O operation on disk, used custom `module.exports` to require directly from a transpiled code string. ## Expected > Added tests for the cases below: - [x] export default - [x] export config `as default` - [x] [config as an async function](https://nextjs.org/docs/app/api-reference/next-config-js) - [x] use Node.js modules (fs, path, etc.) - [x] HMR on config change - [x] throw when type error - [x] turbopack ### Importing Files - [x] nested imports (config -> A -> B) - [x] import alias (tsconfig baseUrl and paths) - [x] import from `node_modules` - [x] import `JSON` #### Extensions - [x] `.ts` - [x] `.cts` - [x] `.mts` - [x] `.cjs` - [x] `.mjs` - [x] `.js` (both ESM and CJS w/o extra change) --------- Co-authored-by: Donny/강동윤 <[email protected]> Co-authored-by: Sukka <[email protected]> Co-authored-by: JJ Kasper <[email protected]> Co-authored-by: Sam Ko <[email protected]> Co-authored-by: Ahmed Abdelbaset <[email protected]> Co-authored-by: JJ Kasper <[email protected]>
Closing due to #63051, thank you for the PR! |
This PR is to support
next.config.ts
, related to discusses #50121