让 IDE 的“转到定义”在全新克隆后无需构建即可工作
ts-monorepo — Next.js 启动器模板
作者 NiGhTTraX
一个用于搭建 TypeScript monorepo 的模板项目,重点让 IDE 的“转到定义”在全新克隆后无需构建即可工作,并提供各工具集成示例。
看看你的网站会是什么样
浏览真实页面截图,比较内容排版与手机效果。点击下方缩略图切换,放大查看整页细节。
目前有 1 张原始预览,可打开完整图片查看设计细节。
截图用于了解视觉与布局,交互效果请以实际项目为准。
值得关注的模板亮点
从已有项目资料中,快速了解它的特点。
为每个包提供干净构建输出,避免混入其他包产物
区分 packages(发布到 npm)与 apps(直接执行)两类工作区
为 packages 提供单独的构建 tsconfig.json,将 monorepo 依赖解析到 node_modules
README 覆盖 ts-node、Babel、webpack、jest、Vite、NextJS、NestJS、Storybook 等集成示例
默认使用 pnpm,同时说明可配合 yarn workspaces、npm workspaces 或 lerna bootstrap
模板详细介绍
该模板围绕 TypeScript monorepo 的两个目标组织:一是让 IDE 的“转到定义”在全新克隆后无需先构建即可正常使用;二是让每个包在发布时获得干净的构建输出,不混入其他包的产物。仓库区分 packages(发布到 npm 并安装)与 apps(直接执行)两类工作区,并为 packages 提供单独的构建 tsconfig.json,把 monorepo 依赖解析到 node_modules。
模板默认使用 pnpm,同时说明也可配合 yarn workspaces、npm 7+ workspaces 或 npm < 7 加 lerna bootstrap 使用,并推荐 pnpm 以避免 hoisting 带来的依赖问题。README 提供了 ts-node、Babel、webpack、jest、Vite、NextJS、NestJS、Storybook 以及已不再支持的 create-react-app 的路径别名解析配置示例,并链接到两篇相关博客文章;如需 project references 方案,可查看 project-references 分支。
使用方式是在 GitHub 页面点击 Use this template,然后按需删减示例、添加所需工具;编译目标、模块系统、tree shaking 等由使用者自行决定。
适合你的项目吗?
适用场景
- 希望在新克隆仓库后直接使用 IDE 跳转定义,而不必先构建整个项目
- 需要把多个包发布到 npm,并让每个包拥有独立、干净的构建输出
- 在同一仓库中同时维护可发布的 packages 和可直接运行的 apps
- 为 ts-node、Babel、webpack、jest、Vite、NextJS、NestJS、Storybook 等工具配置 TypeScript 路径别名
- 想参考 project references 方案,可切换到 project-references 分支
适合人群
- 需要搭建 TypeScript monorepo 并重视 IDE 跳转体验的开发者
- 需要区分可发布包与可执行应用两类工作区的团队
- 使用 pnpm、yarn workspaces 或 npm workspaces 管理多包仓库的项目
- 需要在多种构建与测试工具中统一处理路径别名的项目
上手与定制指南
结合仓库当前版本的说明,按下面的资料检查内容、配置与运行要求。
- 1
在 GitHub 页面点击 Use this template 创建自己的仓库
- 2
默认使用 pnpm:先安装 pnpm,再执行 pnpm i 安装全部依赖
- 3
也可改用 yarn workspaces、npm 7+ workspaces 或 npm < 7 加 lerna bootstrap
- 4
按需删除不需要的示例并添加自己需要的工具
- 5
编译目标、模块系统、tree shaking 等由使用者自行决定
授权与来源资料
使用条件与限制
免费使用 · 保留许可声明本次收录的是公开仓库中采用 MIT 许可的免费版本;免费范围为该版本代码,不代表外部服务或第三方素材免费。
使用时需要遵守
- 允许免费使用、修改、商用和分发该版本代码。
- 分发代码副本或实质性部分时,保留原作者版权声明和完整 MIT 许可声明。
- 代码按现状提供;担保与责任限制以原许可证及适用法律为准。
额外费用与待核对事项
- create-react-app 集成已不再受支持,README 明确标注该方案不可用,使用者不应依赖此集成。
- 作者强烈推荐使用 pnpm,并指出其他包管理器可能因 hoisting 导致依赖问题,属于使用建议而非强制限制。
- 编译目标、模块系统、tree shaking 等配置需由使用者自行决定,模板不提供这些预设。
- 演示图片、字体、图标及其他第三方素材需按各自许可核对,不能仅凭代码的 MIT 许可判断。
- 域名、托管、数据库、支付或 AI 等外部服务可能另外收费。
查看原文依据
Permission is hereby granted, free of charge
许可证原文
Note: this is not supported anymore.
README 原文
I strongly recommend `pnpm`, not only because it's usually faster, but because it avoids dependency problems caused by hoisting
README 原文
https://github.com/NiGhTTraX/ts-monorepo/blob/master/LICENSEhttps://github.com/NiGhTTraX/ts-monorepo/blob/master/README.mdCompilation targets, module systems, tree shaking etc. are left up to you to decide.
README 原文
DeepSeek 根据仓库许可证和 README 整理 ·2026-09-30。结果仅覆盖已读取资料,依赖、图片、字体及后续条款变更以各自原文为准。
项目核对记录与介绍依据
模板资料
- 来源平台
- GitHub
- 资料与维护参考分
- 资料较完整 · 88 / 100
- 技术栈
- Next.js · Vite · React
- 网站类型
- 启动器
这个分数如何计算
本站按许可资料(最高30分)、演示链接(12分)、预览图(10分)、Star数(15分)、记录的维护时间(15分)、描述完整度(8分)、功能记录(5分)和分类资料(5分)计算。它不是代码、安全或性能测试,也不是 Google 评分;有链接不代表已实测可用。
这个项目需要核对什么
- 记录的仓库更新时间
- 2026-09-30
- 截图检查日期
- 2026-09-30
目前没有记录演示链接。请依据仓库说明在本地评估;仅凭截图无法确认交互行为。
目录记录的主要技术栈是 Next.js。请通过依赖清单和锁文件核对实际版本与托管要求。这些说明基于收录资料,不代表代码审计或部署实测。
查看具体选型方法 →介绍的制作与核对状态
介绍由 AI 辅助整理目录与仓库资料。仓库作者不等于这篇介绍的审核者。
已完成服务器许可规则与 AI 来源核对;未经过人工编辑审核。
查看当时使用的来源资料
SHA-256: 1baf9405c241f3e54ee26b038c49404f6e508ad971896c1d86826a367551e850
2026-09-30T07:58:15.594Z
来源文件 / 仓库<!--suppress HtmlDeprecatedAttribute -->
<div align="center">

Template project for setting up a TypeScript monorepo
[](https://github.com/NiGhTTraX/ts-monorepo/actions/workflows/tests.yml)
</div>
----
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of content**
- [Features](#features)
- [Setup](#setup)
- [Docs](#docs)
- [Packages vs apps](#packages-vs-apps)
- [Integrations](#integrations)
- [ts-node](#ts-node)
- [Babel](#babel)
- [webpack](#webpack)
- [jest](#jest)
- [Vite](#vite)
- [NextJS](#nextjs)
- [NestJS](#nestjs)
- [Storybook](#storybook)
- [create-react-app](#create-react-app)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## Features
> The main focus of this repo is making the **`Go to definition`** feature in IDEs work without any surprises, meaning it will work after a fresh clone without needing to build the project.

> The secondary focus is to remove surprises when **publishing** packages. The repo is set up so that each package gets a clean build output without any artifacts from other packages.

## Setup
Click the `Use this template` button at the top of the GitHub page.
This repo uses [pnpm](https://pnpm.io/), but should work fine with any of the following:
- [yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/)
- [npm 7+ workspaces](https://docs.npmjs.com/cli/v7/using-npm/workspaces)
- [npm < 7 and `lerna bootstrap`](https://github.com/lerna/lerna/blob/main/commands/bootstrap/README.md)
I strongly recommend `pnpm`, not only because it's usually faster, but because it avoids dependency problems caused by hoisting (see https://github.com/NiGhTTraX/ts-monorepo/commit/d93139166b25fab15e9538df58a7d06270b846c9 as an example).
```sh
# Install pnpm with your preferred method: https://pnpm.io/installation.
npm i -g pnpm
# Install all dependencies.
pnpm i
```
Then customize the template to your own needs, removing examples you don't need, and adding the tools you do need. Compilation targets, module systems, tree shaking etc. are left up to you to decide.
## Docs
See the following blog posts:
- [How to set up a TypeScript monorepo and make Go to definition work](https://medium.com/@NiGhTTraX/how-to-set-up-a-typescript-monorepo-with-lerna-c6acda7d4559)
- [Making TypeScript monorepos play nice with other tools](https://medium.com/@NiGhTTraX/making-typescript-monorepos-play-nice-with-other-tools-a8d197fdc680)
If you're looking for the project references solution checkout the [`project-references`](https://github.com/NiGhTTraX/ts-monorepo/tree/project-references) branch.
## Packages vs apps
This repo contains two types of workspaces:
- `packages`: meant to be published to npm and installed,
- `apps`: meant to be executed.
A good example to illustrate the difference is `create-react-app`: you wouldn't publish an app like this to npm, you would run it, more specifically you would build the JS bundle and then deploy that somewhere.
For packages, you don't want to bundle all the monorepo dependencies, and instead publish them individually. That's why packages have a separate build `tsconfig.json` that resolves monorepo dependencies to `node_modules`.
## Integrations
### ts-node
Use [tsconfig-paths](https://www.npmjs.com/package/tsconfig-paths) to resolve the path aliases at runtime:
```json
{
"scripts": {
"start": "ts-node -r tsconfig-paths/register src/index.ts"
}
}
```
See the full example [here](apps/ts-node).
### Babel
Use [babel-plugin-module-resolver](https://www.npmjs.com/package/babel-plugin-module-resolver) to resolve the path aliases:
```js
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
plugins: [
[
"module-resolver",
{
alias: {
"^@nighttrax/(.+)": "../\\1/src",
},
},
],
],
};
```
See the full example [here](apps/jest-babel).
### webpack
Use [tsconfig-paths-webpack-plugin](https://www.npmjs.com/package/tsconfig-paths-webpack-plugin) to resolve the path aliases:
```js
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
module.exports = {
resolve: {
plugins: [new TsconfigPathsPlugin()]
}
};
```
See the full example [here](apps/webpack).
### jest
If you use `Babel` then see [this example](apps/jest-babel) from the [Babel](#babel) section above.
If you use [ts-jest](https://github.com/kulshekhar/ts-jest) then you can use its `pathsToModuleNameMapper` helper:
```js
const { pathsToModuleNameMapper } = require("ts-jest");
const { compilerOptions } = require("../../tsconfig.json");
module.exports = {
preset: "ts-jest",
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
// This has to match the baseUrl defined in tsconfig.json.
prefix: "<rootDir>/../../",
}),
};
```
See the full example [here](apps/jest-tsjest).
### Vite
Use [vite-tsconfig-paths](https://www.npmjs.com/package/vite-tsconfig-paths) in the Vite config:
```typescript
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig({
plugins: [
react(),
tsconfigPaths()
],
});
```
See full example [here](apps/vite).
### NextJS
Extend Next's webpack config to enable compiling packages from the monorepo:
```js
module.exports = {
webpack: (config) => {
// Let Babel compile outside of src/.
const tsRule = config.module.rules.find(
(rule) => rule.test && rule.test.toString().includes("tsx|ts")
);
tsRule.include = undefined;
tsRule.exclude = /node_modules/;
return config;
},
};
```
See the full example [here](apps/nextjs).
### NestJS
Include the path aliases in both `tsconfig.json` and `tsconfig.build.json` and tell NestJS where to find the `main.js` file:
```json
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"entryFile": "apps/nestjs/src/main"
}
```
See the full example [here](apps/nestjs).
### Storybook
[Extend Storybook's webpack config](https://storybook.js.org/docs/react/builders/webpack#typescript-module-resolution) and apply the [tsconfig-paths-webpack-plugin](https://www.npmjs.com/package/tsconfig-paths-webpack-plugin):
```js
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
module.exports = {
webpackFinal: async (config) => {
config.resolve.plugins = [
...(config.resolve.plugins || []),
new TsconfigPathsPlugin({
extensions: config.resolve.extensions,
}),
];
return config;
},
};
```
See the full example [here](apps/storybook).
### create-react-app
> Note: this is not supported anymore.
Use [craco](https://www.npmjs.com/package/@craco/craco) or [react-app-rewired](https://www.npmjs.com/package/react-app-rewired) to extend CRA's webpack config and apply the [tsconfig-paths-webpack-plugin](https://www.npmjs.com/package/tsconfig-paths-webpack-plugin):
```js
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
module.exports = (config) => {
// Remove the ModuleScopePlugin which throws when we
// try to import something outside of src/.
config.resolve.plugins.pop();
// Resolve the path aliases.
config.resolve.plugins.push(new TsconfigPathsPlugin());
// Let Babel compile outside of src/.
const oneOfRule = config.module.rules.find((rule) => rule.oneOf);
const tsRule = oneOfRule.oneOf.find((rule) =>
rule.test.toString().includes("ts|tsx")
);
tsRule.include = undefined;
tsRule.exclude = /node_modules/;
return config;
};
```
See the full example [here](https://github.com/NiGhTTraX/ts-monorepo/tree/4222f84e1879a85ffd352fc33c4a8c5167225184/apps/cra). For tests, see the [jest example](#jest).
看看同类模板
对比同技术栈与用途的模板,找到更适合的视觉与内容结构。

ai-website-cloner-template
Clone any website with one command using AI coding agents
Next.js · 启动器

Next.js SaaS Starter
Next.js SaaS Starter 是 Next.js 官方维护的 SaaS 起点模板,定位介于学习资源和可直接部署的脚手架之间。
Next.js · SaaS

Next.js Commerce
Next.js Commerce 是 Vercel 团队维护的电商启动模板,基于 Next.js App Router 构建,采用服务端渲染、React Server Components、Server Actions …
Next.js · 电商

Next-js-Boilerplate
Next-js-Boilerplate 是一个面向 Next.js 16、Tailwind CSS 4 和 TypeScript 的启动器,核心定位是开发者体验优先。
Next.js · 启动器

tailwind-nextjs-starter-blog
tailwind-nextjs-starter-blog 是一个面向个人技术博客的 Next.js 与 Tailwind CSS 启动模板,其 v2 版本基于 App Router 与 React Server Comp…
Next.js · 博客

next-forge
Production-grade Turborepo template for Next.js apps.
Next.js · 启动器
