@jmlweb/tsconfig-nextjs 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +297 -0
- package/package.json +41 -0
- package/tsconfig.json +16 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @jmlweb/tsconfig-nextjs
|
|
2
|
+
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7f42508: Add new TypeScript configuration package for Next.js applications. Extends `@jmlweb/tsconfig-react` with Next.js-specific optimizations including incremental builds, Next.js TypeScript plugin, and pre-configured path aliases. Supports both App Router and Pages Router.
|
package/README.md
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# @jmlweb/tsconfig-nextjs
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@jmlweb/tsconfig-nextjs)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://nextjs.org/)
|
|
8
|
+
|
|
9
|
+
> TypeScript configuration for Next.js applications. Extends `@jmlweb/tsconfig-react` with Next.js-specific optimizations, incremental builds, and path aliases.
|
|
10
|
+
|
|
11
|
+
## ✨ Features
|
|
12
|
+
|
|
13
|
+
- 🔒 **Strict Type Checking**: Inherits all strict TypeScript rules from base configs
|
|
14
|
+
- ⚛️ **React Support**: Full JSX support with modern React transform
|
|
15
|
+
- 🚀 **Next.js Optimized**: Incremental builds and Next.js TypeScript plugin
|
|
16
|
+
- 📁 **Path Aliases**: Pre-configured `@/*` path alias for clean imports
|
|
17
|
+
- 🎯 **App Router Ready**: Optimized for Next.js App Router and Pages Router
|
|
18
|
+
- 🌐 **DOM Types**: Includes DOM and DOM.Iterable libs for browser APIs
|
|
19
|
+
- 📦 **Bundler Resolution**: Optimized `moduleResolution: "bundler"` for Next.js
|
|
20
|
+
|
|
21
|
+
## 📦 Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install --save-dev @jmlweb/tsconfig-nextjs typescript next @jmlweb/tsconfig-react @jmlweb/tsconfig-base
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 🚀 Quick Start
|
|
28
|
+
|
|
29
|
+
Create a `tsconfig.json` file in your Next.js project root:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"extends": "@jmlweb/tsconfig-nextjs",
|
|
34
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
35
|
+
"exclude": ["node_modules"]
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 💡 Examples
|
|
40
|
+
|
|
41
|
+
### Basic Next.js Setup (App Router)
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"extends": "@jmlweb/tsconfig-nextjs",
|
|
46
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
47
|
+
"exclude": ["node_modules"]
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Next.js with Custom Path Aliases
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"extends": "@jmlweb/tsconfig-nextjs",
|
|
56
|
+
"compilerOptions": {
|
|
57
|
+
"paths": {
|
|
58
|
+
"@/*": ["./src/*"],
|
|
59
|
+
"@/components/*": ["./src/components/*"],
|
|
60
|
+
"@/lib/*": ["./src/lib/*"]
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
64
|
+
"exclude": ["node_modules"]
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Next.js Pages Router
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"extends": "@jmlweb/tsconfig-nextjs",
|
|
73
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
|
74
|
+
"exclude": ["node_modules"]
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Next.js with Additional Compiler Options
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"extends": "@jmlweb/tsconfig-nextjs",
|
|
83
|
+
"compilerOptions": {
|
|
84
|
+
"baseUrl": ".",
|
|
85
|
+
"paths": {
|
|
86
|
+
"@/*": ["./src/*"]
|
|
87
|
+
},
|
|
88
|
+
"noEmit": true
|
|
89
|
+
},
|
|
90
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
91
|
+
"exclude": ["node_modules"]
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 📋 Configuration Details
|
|
96
|
+
|
|
97
|
+
### What's Included
|
|
98
|
+
|
|
99
|
+
This configuration extends `@jmlweb/tsconfig-react` and adds:
|
|
100
|
+
|
|
101
|
+
- ✅ **Incremental Builds**: `incremental: true` for faster compilation
|
|
102
|
+
- ✅ **Next.js Plugin**: TypeScript plugin for Next.js-specific type checking
|
|
103
|
+
- ✅ **Path Aliases**: Default `@/*` alias pointing to project root
|
|
104
|
+
- ✅ **All React Config**: Inherits JSX support, DOM types, and bundler resolution
|
|
105
|
+
- ✅ **All Base Config**: Inherits strict type checking and best practices
|
|
106
|
+
|
|
107
|
+
### Next.js TypeScript Plugin
|
|
108
|
+
|
|
109
|
+
The Next.js TypeScript plugin provides:
|
|
110
|
+
|
|
111
|
+
- ✅ Enhanced type checking for Next.js APIs
|
|
112
|
+
- ✅ Better autocomplete for Next.js components
|
|
113
|
+
- ✅ Type safety for App Router and Pages Router
|
|
114
|
+
- ✅ Support for Next.js-specific features
|
|
115
|
+
|
|
116
|
+
### Incremental Builds
|
|
117
|
+
|
|
118
|
+
Incremental compilation:
|
|
119
|
+
|
|
120
|
+
- ✅ Faster subsequent builds
|
|
121
|
+
- ✅ Only recompiles changed files
|
|
122
|
+
- ✅ Stores build information in `.tsbuildinfo` file
|
|
123
|
+
- ✅ Recommended by Next.js for better performance
|
|
124
|
+
|
|
125
|
+
### Path Aliases
|
|
126
|
+
|
|
127
|
+
Default path alias configuration:
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
// Instead of:
|
|
131
|
+
import { Button } from '../../../components/Button';
|
|
132
|
+
|
|
133
|
+
// You can use:
|
|
134
|
+
import { Button } from '@/components/Button';
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The `@/*` alias is pre-configured to point to your project root. You can customize it in your `tsconfig.json`:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"compilerOptions": {
|
|
142
|
+
"paths": {
|
|
143
|
+
"@/*": ["./src/*"]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Note**: Make sure to also configure the same alias in your `next.config.js`:
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
// next.config.js
|
|
153
|
+
module.exports = {
|
|
154
|
+
webpack: (config) => {
|
|
155
|
+
config.resolve.alias = {
|
|
156
|
+
...config.resolve.alias,
|
|
157
|
+
'@': path.resolve(__dirname, './src'),
|
|
158
|
+
};
|
|
159
|
+
return config;
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Or use the built-in Next.js path mapping:
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
// next.config.js
|
|
168
|
+
module.exports = {
|
|
169
|
+
// Next.js 13+ automatically resolves tsconfig paths
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 🎯 When to Use
|
|
174
|
+
|
|
175
|
+
Use this configuration when you want:
|
|
176
|
+
|
|
177
|
+
- ✅ Next.js application development (App Router or Pages Router)
|
|
178
|
+
- ✅ Strict type checking for Next.js code
|
|
179
|
+
- ✅ Incremental builds for faster development
|
|
180
|
+
- ✅ Next.js TypeScript plugin support
|
|
181
|
+
- ✅ Path aliases for cleaner imports
|
|
182
|
+
- ✅ Modern React JSX transform
|
|
183
|
+
- ✅ DOM API type support
|
|
184
|
+
|
|
185
|
+
**For React projects without Next.js**, use [`@jmlweb/tsconfig-react`](../tsconfig-react) instead.
|
|
186
|
+
|
|
187
|
+
**For non-React TypeScript projects**, use [`@jmlweb/tsconfig-base`](../tsconfig-base) instead.
|
|
188
|
+
|
|
189
|
+
## 🔧 Extending the Configuration
|
|
190
|
+
|
|
191
|
+
You can extend or override the configuration for your specific needs:
|
|
192
|
+
|
|
193
|
+
```json
|
|
194
|
+
{
|
|
195
|
+
"extends": "@jmlweb/tsconfig-nextjs",
|
|
196
|
+
"compilerOptions": {
|
|
197
|
+
"baseUrl": ".",
|
|
198
|
+
"paths": {
|
|
199
|
+
"@/*": ["./src/*"],
|
|
200
|
+
"@/components/*": ["./src/components/*"],
|
|
201
|
+
"@/lib/*": ["./src/lib/*"],
|
|
202
|
+
"@/types/*": ["./src/types/*"]
|
|
203
|
+
},
|
|
204
|
+
"noEmit": true
|
|
205
|
+
},
|
|
206
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
207
|
+
"exclude": ["node_modules"]
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Disabling Next.js Plugin
|
|
212
|
+
|
|
213
|
+
If you need to disable the Next.js plugin:
|
|
214
|
+
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"extends": "@jmlweb/tsconfig-nextjs",
|
|
218
|
+
"compilerOptions": {
|
|
219
|
+
"plugins": []
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Customizing Path Aliases
|
|
225
|
+
|
|
226
|
+
Override the default path alias:
|
|
227
|
+
|
|
228
|
+
```json
|
|
229
|
+
{
|
|
230
|
+
"extends": "@jmlweb/tsconfig-nextjs",
|
|
231
|
+
"compilerOptions": {
|
|
232
|
+
"baseUrl": ".",
|
|
233
|
+
"paths": {
|
|
234
|
+
"~/*": ["./src/*"]
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## 📝 Usage with Next.js
|
|
241
|
+
|
|
242
|
+
Next.js handles TypeScript compilation automatically. You typically don't need to run `tsc` manually, but you can add type checking scripts:
|
|
243
|
+
|
|
244
|
+
```json
|
|
245
|
+
{
|
|
246
|
+
"scripts": {
|
|
247
|
+
"dev": "next dev",
|
|
248
|
+
"build": "next build",
|
|
249
|
+
"typecheck": "tsc --noEmit"
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Next.js Type Checking
|
|
255
|
+
|
|
256
|
+
Next.js includes built-in type checking:
|
|
257
|
+
|
|
258
|
+
- ✅ Type errors shown during `next build`
|
|
259
|
+
- ✅ Type errors shown in development mode
|
|
260
|
+
- ✅ IDE integration with TypeScript language server
|
|
261
|
+
|
|
262
|
+
### VS Code Integration
|
|
263
|
+
|
|
264
|
+
For the best experience in VS Code:
|
|
265
|
+
|
|
266
|
+
1. Install the TypeScript extension
|
|
267
|
+
2. Open Command Palette (`Ctrl/⌘ + Shift + P`)
|
|
268
|
+
3. Select "TypeScript: Select TypeScript Version"
|
|
269
|
+
4. Choose "Use Workspace Version"
|
|
270
|
+
|
|
271
|
+
This ensures VS Code uses the Next.js TypeScript plugin for enhanced type checking.
|
|
272
|
+
|
|
273
|
+
## 📋 Requirements
|
|
274
|
+
|
|
275
|
+
- **Node.js** >= 18.0.0
|
|
276
|
+
- **TypeScript** >= 5.0.0
|
|
277
|
+
- **Next.js** >= 13.0.0 (for App Router support)
|
|
278
|
+
- **React** >= 17.0.0 (for JSX runtime support)
|
|
279
|
+
|
|
280
|
+
## 📦 Peer Dependencies
|
|
281
|
+
|
|
282
|
+
This package requires the following peer dependencies:
|
|
283
|
+
|
|
284
|
+
- `typescript` (>= 5.0.0)
|
|
285
|
+
- `next` (>= 13.0.0)
|
|
286
|
+
- `@jmlweb/tsconfig-react` (^1.0.0)
|
|
287
|
+
|
|
288
|
+
## 🔗 Related Packages
|
|
289
|
+
|
|
290
|
+
- [`@jmlweb/tsconfig-react`](../tsconfig-react) - TypeScript configuration for React (extended by this package)
|
|
291
|
+
- [`@jmlweb/tsconfig-base`](../tsconfig-base) - Base TypeScript configuration
|
|
292
|
+
- [`@jmlweb/eslint-config-react`](../eslint-config-react) - ESLint configuration for React/Next.js projects
|
|
293
|
+
- [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier config for consistent formatting
|
|
294
|
+
|
|
295
|
+
## 📄 License
|
|
296
|
+
|
|
297
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jmlweb/tsconfig-nextjs",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "TypeScript configuration for Next.js applications with App Router and Pages Router support",
|
|
5
|
+
"main": "tsconfig.json",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./tsconfig.json"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"tsconfig.json",
|
|
11
|
+
"README.md",
|
|
12
|
+
"CHANGELOG.md"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"config",
|
|
16
|
+
"next.js",
|
|
17
|
+
"nextjs",
|
|
18
|
+
"react",
|
|
19
|
+
"strict",
|
|
20
|
+
"tsconfig",
|
|
21
|
+
"type-checking",
|
|
22
|
+
"typescript"
|
|
23
|
+
],
|
|
24
|
+
"author": "jmlweb",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": "jmlweb/tooling.git",
|
|
27
|
+
"bugs": "https://github.com/jmlweb/tooling/issues",
|
|
28
|
+
"homepage": "https://github.com/jmlweb/tooling/tree/main/packages/tsconfig-nextjs#readme",
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@jmlweb/tsconfig-react": "^1.0.0",
|
|
37
|
+
"next": ">=13.0.0",
|
|
38
|
+
"typescript": ">=5.0.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {}
|
|
41
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"display": "@jmlweb/tsconfig-nextjs",
|
|
4
|
+
"extends": "@jmlweb/tsconfig-react",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"incremental": true,
|
|
7
|
+
"plugins": [
|
|
8
|
+
{
|
|
9
|
+
"name": "next"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"paths": {
|
|
13
|
+
"@/*": ["./*"]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|