pageExtensions
你可以扩展 Next.js 使用的默认页面扩展(.tsx
、.ts
、.jsx
、.js
)。在 next.config.js
中,添加 pageExtensions
配置:
¥You can extend the default Page extensions (.tsx
, .ts
, .jsx
, .js
) used by Next.js. Inside next.config.js
, add the pageExtensions
config:
更改这些值会影响所有 Next.js 页面,包括以下页面:
¥Changing these values affects all Next.js pages, including the following:
pages/_document.js
pages/_app.js
pages/api/
例如,如果你将 .ts
页面扩展重新配置为 .page.ts
,则需要重命名像 middleware.page.ts
、instrumentation.page.ts
、_app.page.ts
这样的页面。
¥For example, if you reconfigure .ts
page extensions to .page.ts
, you would need to rename pages like middleware.page.ts
, instrumentation.page.ts
, _app.page.ts
.
在 pages
目录中包含非页面文件
¥Including non-page files in the pages
directory
你可以将测试文件或组件使用的其他文件共置在 pages
目录中。在 next.config.js
中,添加 pageExtensions
配置:
¥You can colocate test files or other files used by components in the pages
directory. Inside next.config.js
, add the pageExtensions
config:
然后,将页面重命名为包含 .page
的文件扩展名(例如,将 MyPage.tsx
重命名为 MyPage.page.tsx
)。确保重命名所有 Next.js 页面,包括上述文件。
¥Then, rename your pages to have a file extension that includes .page
(e.g. rename MyPage.tsx
to MyPage.page.tsx
). Ensure you rename all Next.js pages, including the files mentioned above.