create-rsc-kit 0.8.0 → 0.9.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/dist/templates.js +34 -4
- package/package.json +1 -1
package/dist/templates.js
CHANGED
|
@@ -196,7 +196,11 @@ export function viteConfig(o) {
|
|
|
196
196
|
//
|
|
197
197
|
// Not optional, and not a flag on rscKit() either — the plugin builds for
|
|
198
198
|
// Nitro and nothing else, so a config without this line has no server.
|
|
199
|
-
|
|
199
|
+
// serverDir is what makes server/api and server/routes exist at all: Nitro's
|
|
200
|
+
// scanDirs is empty without it, so a handler written there is never scanned,
|
|
201
|
+
// the request falls through to the rsc entry, and the 404 it answers with
|
|
202
|
+
// reads as a routing bug in this package rather than a missing option.
|
|
203
|
+
plugins.push(`nitro({ preset: ${JSON.stringify(preset(o.host))}, serveStatic: 'inline', serverDir: 'server' })`);
|
|
200
204
|
plugins.push(`rscKit({
|
|
201
205
|
${options.join(',\n ')},
|
|
202
206
|
})`);
|
|
@@ -205,12 +209,22 @@ export function viteConfig(o) {
|
|
|
205
209
|
plugins.push('babel({ presets: [reactCompilerPreset()] })');
|
|
206
210
|
if (o.tailwind)
|
|
207
211
|
plugins.push('tailwindcss()');
|
|
212
|
+
// `@/` for the source directory. Vite does not read tsconfig `paths`, so the
|
|
213
|
+
// alias has to exist here as well or the import type-checks and then fails to
|
|
214
|
+
// resolve — and the tsconfig half is what tools like shadcn look for when
|
|
215
|
+
// they ask whether this project has an import alias at all.
|
|
208
216
|
return `${imports.join('\n')}
|
|
217
|
+
import { fileURLToPath } from 'node:url'
|
|
209
218
|
|
|
210
219
|
export default defineConfig({
|
|
211
220
|
plugins: [
|
|
212
221
|
${plugins.join(',\n ')},
|
|
213
222
|
],
|
|
223
|
+
resolve: {
|
|
224
|
+
alias: {
|
|
225
|
+
'@': fileURLToPath(new URL('./${o.sourceDir}', import.meta.url)),
|
|
226
|
+
},
|
|
227
|
+
},
|
|
214
228
|
})
|
|
215
229
|
`;
|
|
216
230
|
}
|
|
@@ -220,6 +234,16 @@ export const tsconfig = (o) => JSON.stringify({
|
|
|
220
234
|
target: 'ESNext',
|
|
221
235
|
module: 'ESNext',
|
|
222
236
|
moduleResolution: 'bundler',
|
|
237
|
+
// `@/thing` for `<sourceDir>/thing`. Matched by resolve.alias in the
|
|
238
|
+
// vite config, which is what actually resolves it — this half is for
|
|
239
|
+
// the type system, and for the tools that read a tsconfig to find out
|
|
240
|
+
// whether the project has an import alias. shadcn refuses to init
|
|
241
|
+
// without one.
|
|
242
|
+
//
|
|
243
|
+
// No `baseUrl`: TypeScript removed it, and emitting it now is an
|
|
244
|
+
// outright TS5102 on a freshly scaffolded app. Paths resolve relative
|
|
245
|
+
// to this file without it.
|
|
246
|
+
paths: { '@/*': [`./${o.sourceDir}/*`] },
|
|
223
247
|
jsx: 'react-jsx',
|
|
224
248
|
strict: true,
|
|
225
249
|
noEmit: true,
|
|
@@ -249,12 +273,17 @@ export const tsconfig = (o) => JSON.stringify({
|
|
|
249
273
|
// .rsc-kit holds the generated ambient declarations. Ambient means
|
|
250
274
|
// inside the project, and `include` is what decides that — leave it out
|
|
251
275
|
// and typed routes silently fall back to string.
|
|
252
|
-
|
|
276
|
+
//
|
|
277
|
+
// server/ is the same mistake one directory over: an api handler outside
|
|
278
|
+
// the program is not type-checked at all, so one returning the wrong
|
|
279
|
+
// shape builds, deploys and fails at runtime with nothing having said so.
|
|
280
|
+
include: [`${o.sourceDir}/**/*`, 'server/**/*', '.rsc-kit/**/*'],
|
|
253
281
|
}, null, 2) + '\n';
|
|
254
282
|
export function layout(o) {
|
|
255
283
|
return `${o.tailwind ? "import './styles.css'\n" : ''}import type { ReactNode } from 'react'
|
|
284
|
+
import type { Metadata } from '@rsc-kit/core/metadata'
|
|
256
285
|
|
|
257
|
-
export const metadata = {
|
|
286
|
+
export const metadata: Metadata = {
|
|
258
287
|
title: { template: '%s · ${o.name}', default: '${o.name}' },
|
|
259
288
|
}
|
|
260
289
|
|
|
@@ -288,8 +317,9 @@ export function page(o) {
|
|
|
288
317
|
// did was look broken, and the fix someone reaches for is to stop
|
|
289
318
|
// prerendering the page that is teaching them about prerendering.
|
|
290
319
|
return `import { Counter } from '../components/Counter'
|
|
320
|
+
import type { Metadata } from '@rsc-kit/core/metadata'
|
|
291
321
|
|
|
292
|
-
export const metadata = { title: 'Home' }
|
|
322
|
+
export const metadata: Metadata = { title: 'Home' }
|
|
293
323
|
|
|
294
324
|
// A server component. It runs on the server and ships no JavaScript of its
|
|
295
325
|
// own — this file is not in the browser bundle. It can be \`async\` and await
|