Skip to content

Commit 997d621

Browse files
committed
feat(nitro): add runtime app and render exports
- Implemented `app.ts` to export `useNitroApp`. - Implemented `render.ts` to export `defineRenderHandler`. feat(nitro): add runtime types exports - Created `index.ts` to export types: `NitroApp`, `RenderResponse`, and `RenderHandler`. feat(nuxt): add core exports and page scanning functionality - Implemented `index.ts` to export `loadNuxt` and `buildDir`. - Added `scan.ts` to scan pages and generate routes code. feat(vite): add virtual plugin for Vite - Implemented `virtual.ts` to create a Vite plugin for handling virtual file system.
1 parent 535f412 commit 997d621

File tree

21 files changed

+1458
-1103
lines changed

21 files changed

+1458
-1103
lines changed

docs/.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from 'vitepress'
22

33
// https://vitepress.dev/reference/site-config
44
export default defineConfig({
5+
base: '/chibinuxt/',
56
title: 'chibinuxt',
67
description: 'Build Your Own Nuxt - A Retro Adventure',
78
srcDir: 'src',

impls/7-pages/packages/nuxt/src/app/plugins/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
createMemoryHistory,
44
createWebHistory,
55
} from 'vue-router'
6-
6+
// @ts-expect-error virtual module
77
import routes from '#routes'
88

99
export const createRouter = () => {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { useNitroApp } from './internal/app'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { defineRenderHandler } from './internal/render'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type { NitroApp, RenderResponse, RenderHandler } from './nitro'

impls/9-nitro-rolldown/packages/nuxt/build.config.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,15 @@ export default defineBuildConfig({
44
declaration: true,
55
entries: [
66
// Core
7-
{ input: 'src/index.mts' },
7+
{ input: 'src/index.ts' },
88
// App
99
{ input: 'src/app/', outDir: 'dist/app/', ext: 'js' },
10-
// Runtime dirs
11-
...['core', 'pages'].map(
12-
name =>
13-
({
14-
input: `src/${name}/runtime/`,
15-
outDir: `dist/${name}/runtime`,
16-
format: 'esm',
17-
ext: 'js',
18-
}) as BuildEntry,
19-
),
10+
// Runtime
11+
{ input: 'src/core/runtime/', outDir: 'dist/core/runtime', format: 'esm', ext: 'js' },
12+
// Bin
2013
{ input: 'src/bin.ts' },
2114
],
2215
alias: {
23-
['nuxt']: 'nuxt', // this is necessary for resolveAlias not to change id (https://github.com/unjs/unbuild/blob/997497b356b2ebe19112d2f6436a349a74885d68/src/builders/rollup/config.ts#L65)
16+
['nuxt']: 'nuxt',
2417
},
2518
})

impls/9-nitro-rolldown/packages/nuxt/src/app/entry.client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createSSRApp } from 'vue'
2-
import App from '../../../../playground/App.vue'
32
import { createRouter } from './plugins/router'
3+
// @ts-expect-error virtual module
4+
import App from '#app'
45

56
const initApp = async () => {
67
const router = createRouter()

impls/9-nitro-rolldown/packages/nuxt/src/app/entry.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createSSRApp } from 'vue'
2-
import App from '../../../../playground/App.vue'
32
import { createRouter } from './plugins/router'
3+
// @ts-expect-error virtual module
4+
import App from '#app'
45

56
export default async (ctx: { url: string }) => {
67
const app = createSSRApp(App)

impls/9-nitro-rolldown/packages/nuxt/src/app/plugins/router.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
import {
2-
type RouteRecordRaw,
32
createRouter as _createRouter,
43
createMemoryHistory,
54
createWebHistory,
65
} from 'vue-router'
7-
import Hello from '../../../../../playground/pages/hello.vue'
8-
import World from '../../../../../playground/pages/world.vue'
6+
// @ts-expect-error virtual module
7+
import routes from '#routes'
98

109
export const createRouter = () => {
11-
const routes = [
12-
{
13-
path: '/hello',
14-
component: Hello,
15-
},
16-
{
17-
path: '/world',
18-
component: World,
19-
},
20-
] satisfies RouteRecordRaw[]
2110
const history = import.meta.server
2211
? createMemoryHistory()
2312
: createWebHistory()

impls/9-nitro-rolldown/packages/nuxt/src/bin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#!/usr/bin/env node
2-
import { loadNuxt } from './index.mjs'
1+
#!/usr/bin/env bun
2+
import { loadNuxt } from './core/nuxt'
33

44
const main = async () => {
5-
process.env.DIST_DIR = import.meta.dirname
65
const nuxt = await loadNuxt()
76
nuxt.server.listen()
87
}

0 commit comments

Comments
 (0)