@depup/nitro 3.0.260311-beta-depup.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/LICENSE +27 -0
- package/README.md +32 -0
- package/changes.json +14 -0
- package/dist/THIRD-PARTY-LICENSES.md +1646 -0
- package/dist/_build/common.mjs +29361 -0
- package/dist/_build/rolldown.mjs +173 -0
- package/dist/_build/rollup.mjs +194 -0
- package/dist/_build/vite.build.mjs +18 -0
- package/dist/_chunks/nitro.mjs +1159 -0
- package/dist/_chunks/nitro2.mjs +102 -0
- package/dist/_chunks/nitro3.mjs +129 -0
- package/dist/_chunks/utils.mjs +272 -0
- package/dist/_common.mjs +35 -0
- package/dist/_dev.d.mts +12 -0
- package/dist/_dev.mjs +519 -0
- package/dist/_libs/_.mjs +3 -0
- package/dist/_libs/_2.mjs +2 -0
- package/dist/_libs/_3.mjs +3 -0
- package/dist/_libs/_4.mjs +2 -0
- package/dist/_libs/_5.mjs +3 -0
- package/dist/_libs/_6.mjs +4 -0
- package/dist/_libs/_7.mjs +5 -0
- package/dist/_libs/c12+rc9.mjs +812 -0
- package/dist/_libs/c12+readdirp+chokidar.d.mts +230 -0
- package/dist/_libs/citty.mjs +361 -0
- package/dist/_libs/commondir+is-reference.mjs +1311 -0
- package/dist/_libs/compatx.d.mts +47 -0
- package/dist/_libs/compatx.mjs +45 -0
- package/dist/_libs/esbuild.d.mts +20 -0
- package/dist/_libs/escape-string-regexp.mjs +7 -0
- package/dist/_libs/estree+pluginutils.d.mts +241 -0
- package/dist/_libs/estree-walker.mjs +184 -0
- package/dist/_libs/exsolve.d.mts +1 -0
- package/dist/_libs/hasown+resolve+deepmerge.mjs +1949 -0
- package/dist/_libs/httpxy.d.mts +82 -0
- package/dist/_libs/httpxy.mjs +671 -0
- package/dist/_libs/js-tokens.d.mts +1 -0
- package/dist/_libs/klona.mjs +37 -0
- package/dist/_libs/magic-string.d.mts +220 -0
- package/dist/_libs/mlly.d.mts +57 -0
- package/dist/_libs/nypm+tinyexec.mjs +845 -0
- package/dist/_libs/perfect-debounce.mjs +88 -0
- package/dist/_libs/pkg-types.d.mts +23 -0
- package/dist/_libs/plugin-alias.mjs +64 -0
- package/dist/_libs/plugin-inject.mjs +131 -0
- package/dist/_libs/plugin-json.mjs +34 -0
- package/dist/_libs/pluginutils.mjs +646 -0
- package/dist/_libs/readdirp+chokidar.mjs +1606 -0
- package/dist/_libs/remapping.mjs +115 -0
- package/dist/_libs/resolve-uri+gen-mapping.mjs +442 -0
- package/dist/_libs/rou3.d.mts +44 -0
- package/dist/_libs/rou3.mjs +496 -0
- package/dist/_libs/std-env.d.mts +12 -0
- package/dist/_libs/strip-literal.d.mts +1 -0
- package/dist/_libs/tsconfck.mjs +813 -0
- package/dist/_libs/ultrahtml.mjs +127 -0
- package/dist/_libs/unimport+unplugin.mjs +1684 -0
- package/dist/_libs/unplugin+unimport.d.mts +423 -0
- package/dist/_libs/unwasm.d.mts +29 -0
- package/dist/_presets.mjs +1759 -0
- package/dist/builder.d.mts +64 -0
- package/dist/builder.mjs +15 -0
- package/dist/cli/_chunks/build.mjs +47 -0
- package/dist/cli/_chunks/common.mjs +14 -0
- package/dist/cli/_chunks/deploy.mjs +40 -0
- package/dist/cli/_chunks/dev.mjs +62 -0
- package/dist/cli/_chunks/docs.mjs +30 -0
- package/dist/cli/_chunks/list.mjs +25 -0
- package/dist/cli/_chunks/prepare.mjs +17 -0
- package/dist/cli/_chunks/preview.mjs +51 -0
- package/dist/cli/_chunks/run.mjs +53 -0
- package/dist/cli/_chunks/task.mjs +14 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +22 -0
- package/dist/node_modules/@poppinss/colors/build/index.js +139 -0
- package/dist/node_modules/@poppinss/colors/package.json +118 -0
- package/dist/node_modules/@poppinss/dumper/build/chunk-26HALFTP.js +602 -0
- package/dist/node_modules/@poppinss/dumper/build/formatters/console/main.js +441 -0
- package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +725 -0
- package/dist/node_modules/@poppinss/dumper/package.json +122 -0
- package/dist/node_modules/@poppinss/exception/build/index.js +44 -0
- package/dist/node_modules/@poppinss/exception/package.json +109 -0
- package/dist/node_modules/@sindresorhus/is/distribution/index.js +1354 -0
- package/dist/node_modules/@sindresorhus/is/distribution/utilities.js +3 -0
- package/dist/node_modules/@sindresorhus/is/package.json +81 -0
- package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -0
- package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -0
- package/dist/node_modules/@speed-highlight/core/package.json +94 -0
- package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
- package/dist/node_modules/cookie-es/package.json +37 -0
- package/dist/node_modules/croner/dist/croner.js +1 -0
- package/dist/node_modules/croner/package.json +73 -0
- package/dist/node_modules/defu/dist/defu.mjs +69 -0
- package/dist/node_modules/defu/package.json +43 -0
- package/dist/node_modules/destr/dist/index.mjs +72 -0
- package/dist/node_modules/destr/package.json +47 -0
- package/dist/node_modules/error-stack-parser-es/dist/index.mjs +38 -0
- package/dist/node_modules/error-stack-parser-es/dist/lite.mjs +167 -0
- package/dist/node_modules/error-stack-parser-es/package.json +83 -0
- package/dist/node_modules/get-port-please/dist/index.mjs +430 -0
- package/dist/node_modules/get-port-please/package.json +39 -0
- package/dist/node_modules/kleur/index.mjs +110 -0
- package/dist/node_modules/kleur/package.json +51 -0
- package/dist/node_modules/rendu/dist/index.mjs +380 -0
- package/dist/node_modules/rendu/package.json +47 -0
- package/dist/node_modules/scule/dist/index.mjs +80 -0
- package/dist/node_modules/scule/package.json +43 -0
- package/dist/node_modules/source-map/lib/array-set.js +100 -0
- package/dist/node_modules/source-map/lib/base64-vlq.js +94 -0
- package/dist/node_modules/source-map/lib/base64.js +19 -0
- package/dist/node_modules/source-map/lib/binary-search.js +113 -0
- package/dist/node_modules/source-map/lib/mapping-list.js +83 -0
- package/dist/node_modules/source-map/lib/mappings.wasm +0 -0
- package/dist/node_modules/source-map/lib/read-wasm.js +27 -0
- package/dist/node_modules/source-map/lib/source-map-consumer.js +1081 -0
- package/dist/node_modules/source-map/lib/source-map-generator.js +439 -0
- package/dist/node_modules/source-map/lib/source-node.js +430 -0
- package/dist/node_modules/source-map/lib/url.js +13 -0
- package/dist/node_modules/source-map/lib/util.js +444 -0
- package/dist/node_modules/source-map/lib/wasm.js +138 -0
- package/dist/node_modules/source-map/package.json +79 -0
- package/dist/node_modules/source-map/source-map.js +10 -0
- package/dist/node_modules/supports-color/index.js +202 -0
- package/dist/node_modules/supports-color/package.json +64 -0
- package/dist/node_modules/ufo/dist/index.mjs +645 -0
- package/dist/node_modules/ufo/package.json +48 -0
- package/dist/node_modules/unctx/dist/index.mjs +131 -0
- package/dist/node_modules/unctx/package.json +67 -0
- package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
- package/dist/node_modules/youch/build/index.js +212 -0
- package/dist/node_modules/youch/build/public/error_cause/style.css +5 -0
- package/dist/node_modules/youch/build/public/error_info/script.js +13 -0
- package/dist/node_modules/youch/build/public/error_info/style.css +145 -0
- package/dist/node_modules/youch/build/public/error_metadata/style.css +3 -0
- package/dist/node_modules/youch/build/public/error_stack/script.js +72 -0
- package/dist/node_modules/youch/build/public/error_stack/style.css +219 -0
- package/dist/node_modules/youch/build/public/error_stack_source/style.css +123 -0
- package/dist/node_modules/youch/build/public/header/script.js +14 -0
- package/dist/node_modules/youch/build/public/header/style.css +56 -0
- package/dist/node_modules/youch/build/public/layout/script.js +12 -0
- package/dist/node_modules/youch/build/public/layout/style.css +435 -0
- package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
- package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
- package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
- package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
- package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
- package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
- package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
- package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
- package/dist/node_modules/youch/package.json +135 -0
- package/dist/node_modules/youch-core/build/index.js +316 -0
- package/dist/node_modules/youch-core/package.json +124 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +20 -0
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +15 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +23 -0
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +14 -0
- package/dist/presets/aws-lambda/runtime/_utils.mjs +116 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +31 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +13 -0
- package/dist/presets/azure/runtime/_utils.mjs +50 -0
- package/dist/presets/azure/runtime/azure-swa.mjs +30 -0
- package/dist/presets/bun/runtime/bun.mjs +40 -0
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +87 -0
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +72 -0
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +17 -0
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +39 -0
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +96 -0
- package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +19 -0
- package/dist/presets/deno/runtime/deno-server.mjs +39 -0
- package/dist/presets/netlify/runtime/netlify-edge.mjs +20 -0
- package/dist/presets/netlify/runtime/netlify.mjs +20 -0
- package/dist/presets/node/runtime/node-cluster.mjs +54 -0
- package/dist/presets/node/runtime/node-middleware.mjs +14 -0
- package/dist/presets/node/runtime/node-server.mjs +47 -0
- package/dist/presets/standard/runtime/server.mjs +4 -0
- package/dist/presets/stormkit/runtime/stormkit.mjs +27 -0
- package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
- package/dist/presets/vercel/runtime/isr.mjs +19 -0
- package/dist/presets/vercel/runtime/vercel.node.mjs +24 -0
- package/dist/presets/vercel/runtime/vercel.web.mjs +23 -0
- package/dist/presets/winterjs/runtime/winterjs.mjs +91 -0
- package/dist/presets/zeabur/runtime/zeabur.mjs +4 -0
- package/dist/presets/zephyr/runtime/server.mjs +3 -0
- package/dist/runtime/app.d.mts +1 -0
- package/dist/runtime/app.mjs +1 -0
- package/dist/runtime/cache.d.mts +1 -0
- package/dist/runtime/cache.mjs +1 -0
- package/dist/runtime/config.d.mts +3 -0
- package/dist/runtime/config.mjs +4 -0
- package/dist/runtime/context.d.mts +1 -0
- package/dist/runtime/context.mjs +1 -0
- package/dist/runtime/database.d.mts +1 -0
- package/dist/runtime/database.mjs +1 -0
- package/dist/runtime/internal/app.d.mts +16 -0
- package/dist/runtime/internal/app.mjs +208 -0
- package/dist/runtime/internal/cache.d.mts +7 -0
- package/dist/runtime/internal/cache.mjs +41 -0
- package/dist/runtime/internal/context.d.mts +14 -0
- package/dist/runtime/internal/context.mjs +24 -0
- package/dist/runtime/internal/database.d.mts +2 -0
- package/dist/runtime/internal/database.mjs +12 -0
- package/dist/runtime/internal/empty.mjs +0 -0
- package/dist/runtime/internal/error/dev.d.mts +10 -0
- package/dist/runtime/internal/error/dev.mjs +121 -0
- package/dist/runtime/internal/error/hooks.d.mts +1 -0
- package/dist/runtime/internal/error/hooks.mjs +9 -0
- package/dist/runtime/internal/error/prod.d.mts +6 -0
- package/dist/runtime/internal/error/prod.mjs +40 -0
- package/dist/runtime/internal/error/utils.d.mts +8 -0
- package/dist/runtime/internal/error/utils.mjs +3 -0
- package/dist/runtime/internal/meta.d.mts +2 -0
- package/dist/runtime/internal/meta.mjs +3 -0
- package/dist/runtime/internal/plugin.d.mts +3 -0
- package/dist/runtime/internal/plugin.mjs +4 -0
- package/dist/runtime/internal/route-rules.d.mts +9 -0
- package/dist/runtime/internal/route-rules.mjs +72 -0
- package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -0
- package/dist/runtime/internal/routes/dev-tasks.mjs +25 -0
- package/dist/runtime/internal/routes/openapi.d.mts +3 -0
- package/dist/runtime/internal/routes/openapi.mjs +94 -0
- package/dist/runtime/internal/routes/renderer-template.d.mts +2 -0
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +3 -0
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +19 -0
- package/dist/runtime/internal/routes/renderer-template.mjs +4 -0
- package/dist/runtime/internal/routes/scalar.d.mts +3 -0
- package/dist/runtime/internal/routes/scalar.mjs +193 -0
- package/dist/runtime/internal/routes/swagger.d.mts +3 -0
- package/dist/runtime/internal/routes/swagger.mjs +42 -0
- package/dist/runtime/internal/runtime-config.d.mts +9 -0
- package/dist/runtime/internal/runtime-config.mjs +54 -0
- package/dist/runtime/internal/static.d.mts +3 -0
- package/dist/runtime/internal/static.mjs +67 -0
- package/dist/runtime/internal/storage.d.mts +2 -0
- package/dist/runtime/internal/storage.mjs +6 -0
- package/dist/runtime/internal/task.d.mts +19 -0
- package/dist/runtime/internal/task.mjs +69 -0
- package/dist/runtime/internal/vite/dev-entry.mjs +18 -0
- package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
- package/dist/runtime/internal/vite/ssr-renderer.mjs +6 -0
- package/dist/runtime/meta.d.mts +5 -0
- package/dist/runtime/meta.mjs +27 -0
- package/dist/runtime/nitro.d.mts +11 -0
- package/dist/runtime/nitro.mjs +34 -0
- package/dist/runtime/runtime-config.d.mts +1 -0
- package/dist/runtime/runtime-config.mjs +1 -0
- package/dist/runtime/storage.d.mts +1 -0
- package/dist/runtime/storage.mjs +1 -0
- package/dist/runtime/task.d.mts +1 -0
- package/dist/runtime/task.mjs +1 -0
- package/dist/runtime/virtual/_runtime_warn.d.mts +1 -0
- package/dist/runtime/virtual/_runtime_warn.mjs +5 -0
- package/dist/runtime/virtual/database.d.mts +8 -0
- package/dist/runtime/virtual/database.mjs +2 -0
- package/dist/runtime/virtual/error-handler.d.mts +6 -0
- package/dist/runtime/virtual/error-handler.mjs +9 -0
- package/dist/runtime/virtual/feature-flags.d.mts +7 -0
- package/dist/runtime/virtual/feature-flags.mjs +7 -0
- package/dist/runtime/virtual/plugins.d.mts +3 -0
- package/dist/runtime/virtual/plugins.mjs +2 -0
- package/dist/runtime/virtual/polyfills.d.mts +3 -0
- package/dist/runtime/virtual/polyfills.mjs +2 -0
- package/dist/runtime/virtual/public-assets.d.mts +9 -0
- package/dist/runtime/virtual/public-assets.mjs +8 -0
- package/dist/runtime/virtual/renderer-template.d.mts +4 -0
- package/dist/runtime/virtual/renderer-template.mjs +7 -0
- package/dist/runtime/virtual/routing-meta.d.mts +7 -0
- package/dist/runtime/virtual/routing-meta.mjs +2 -0
- package/dist/runtime/virtual/routing.d.mts +8 -0
- package/dist/runtime/virtual/routing.mjs +11 -0
- package/dist/runtime/virtual/runtime-config.d.mts +3 -0
- package/dist/runtime/virtual/runtime-config.mjs +5 -0
- package/dist/runtime/virtual/server-assets.d.mts +7 -0
- package/dist/runtime/virtual/server-assets.mjs +12 -0
- package/dist/runtime/virtual/storage.d.mts +3 -0
- package/dist/runtime/virtual/storage.mjs +5 -0
- package/dist/runtime/virtual/tasks.d.mts +10 -0
- package/dist/runtime/virtual/tasks.mjs +3 -0
- package/dist/runtime/vite.d.mts +8 -0
- package/dist/runtime/vite.mjs +9 -0
- package/dist/types/index.d.mts +3010 -0
- package/dist/types/index.mjs +1 -0
- package/dist/vite.d.mts +52 -0
- package/dist/vite.mjs +740 -0
- package/lib/h3.d.mts +1 -0
- package/lib/h3.mjs +1 -0
- package/lib/tsconfig.json +27 -0
- package/lib/vite.types.d.mts +26 -0
- package/lib/vite.types.mjs +2 -0
- package/package.json +256 -0
- package/skills/nitro/SKILL.md +10 -0
- package/skills/nitro/docs/TOC.md +83 -0
- package/skills/nitro/docs/_navigation.json +679 -0
- package/skills/nitro/docs/config/index.md +1147 -0
- package/skills/nitro/docs/deploy/index.md +64 -0
- package/skills/nitro/docs/deploy/providers/alwaysdata.md +50 -0
- package/skills/nitro/docs/deploy/providers/aws-amplify.md +81 -0
- package/skills/nitro/docs/deploy/providers/aws.md +47 -0
- package/skills/nitro/docs/deploy/providers/azure.md +72 -0
- package/skills/nitro/docs/deploy/providers/cleavr.md +33 -0
- package/skills/nitro/docs/deploy/providers/cloudflare.md +375 -0
- package/skills/nitro/docs/deploy/providers/deno-deploy.md +66 -0
- package/skills/nitro/docs/deploy/providers/digitalocean.md +46 -0
- package/skills/nitro/docs/deploy/providers/firebase.md +32 -0
- package/skills/nitro/docs/deploy/providers/flightcontrol.md +67 -0
- package/skills/nitro/docs/deploy/providers/genezio.md +67 -0
- package/skills/nitro/docs/deploy/providers/github-pages.md +68 -0
- package/skills/nitro/docs/deploy/providers/gitlab-pages.md +37 -0
- package/skills/nitro/docs/deploy/providers/heroku.md +84 -0
- package/skills/nitro/docs/deploy/providers/iis.md +38 -0
- package/skills/nitro/docs/deploy/providers/koyeb.md +109 -0
- package/skills/nitro/docs/deploy/providers/netlify.md +47 -0
- package/skills/nitro/docs/deploy/providers/platform-sh.md +37 -0
- package/skills/nitro/docs/deploy/providers/render.md +37 -0
- package/skills/nitro/docs/deploy/providers/stormkit.md +24 -0
- package/skills/nitro/docs/deploy/providers/vercel.md +179 -0
- package/skills/nitro/docs/deploy/providers/zeabur.md +19 -0
- package/skills/nitro/docs/deploy/providers/zephyr.md +99 -0
- package/skills/nitro/docs/deploy/providers/zerops.md +102 -0
- package/skills/nitro/docs/deploy/runtimes/bun.md +15 -0
- package/skills/nitro/docs/deploy/runtimes/deno.md +19 -0
- package/skills/nitro/docs/deploy/runtimes/node.md +63 -0
- package/skills/nitro/docs/docs/assets.md +166 -0
- package/skills/nitro/docs/docs/cache.md +408 -0
- package/skills/nitro/docs/docs/configuration.md +256 -0
- package/skills/nitro/docs/docs/database.md +185 -0
- package/skills/nitro/docs/docs/index.md +56 -0
- package/skills/nitro/docs/docs/lifecycle.md +204 -0
- package/skills/nitro/docs/docs/migration.md +215 -0
- package/skills/nitro/docs/docs/nightly.md +31 -0
- package/skills/nitro/docs/docs/plugins.md +164 -0
- package/skills/nitro/docs/docs/quick-start.md +110 -0
- package/skills/nitro/docs/docs/renderer.md +322 -0
- package/skills/nitro/docs/docs/routing.md +711 -0
- package/skills/nitro/docs/docs/server-entry.md +239 -0
- package/skills/nitro/docs/docs/storage.md +261 -0
- package/skills/nitro/docs/docs/tasks.md +277 -0
- package/skills/nitro/docs/examples/api-routes.md +145 -0
- package/skills/nitro/docs/examples/auto-imports.md +93 -0
- package/skills/nitro/docs/examples/cached-handler.md +81 -0
- package/skills/nitro/docs/examples/custom-error-handler.md +98 -0
- package/skills/nitro/docs/examples/database.md +157 -0
- package/skills/nitro/docs/examples/elysia.md +70 -0
- package/skills/nitro/docs/examples/express.md +78 -0
- package/skills/nitro/docs/examples/fastify.md +79 -0
- package/skills/nitro/docs/examples/hello-world.md +68 -0
- package/skills/nitro/docs/examples/hono.md +74 -0
- package/skills/nitro/docs/examples/import-alias.md +100 -0
- package/skills/nitro/docs/examples/index.md +3 -0
- package/skills/nitro/docs/examples/middleware.md +91 -0
- package/skills/nitro/docs/examples/mono-jsx.md +68 -0
- package/skills/nitro/docs/examples/nano-jsx.md +70 -0
- package/skills/nitro/docs/examples/plugins.md +91 -0
- package/skills/nitro/docs/examples/renderer.md +113 -0
- package/skills/nitro/docs/examples/runtime-config.md +97 -0
- package/skills/nitro/docs/examples/server-fetch.md +87 -0
- package/skills/nitro/docs/examples/shiki.md +198 -0
- package/skills/nitro/docs/examples/virtual-routes.md +74 -0
- package/skills/nitro/docs/examples/vite-nitro-plugin.md +79 -0
- package/skills/nitro/docs/examples/vite-rsc.md +1041 -0
- package/skills/nitro/docs/examples/vite-ssr-html.md +217 -0
- package/skills/nitro/docs/examples/vite-ssr-preact.md +247 -0
- package/skills/nitro/docs/examples/vite-ssr-react.md +226 -0
- package/skills/nitro/docs/examples/vite-ssr-solid.md +256 -0
- package/skills/nitro/docs/examples/vite-ssr-tsr-react.md +442 -0
- package/skills/nitro/docs/examples/vite-ssr-tss-react.md +444 -0
- package/skills/nitro/docs/examples/vite-ssr-vue-router.md +616 -0
- package/skills/nitro/docs/examples/vite-trpc.md +335 -0
- package/skills/nitro/docs/examples/websocket.md +282 -0
- package/skills/nitro/docs/index.md +121 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# Database
|
|
2
|
+
|
|
3
|
+
> Built-in database support with SQL template literals.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
experimental: {
|
|
12
|
+
database: true,
|
|
13
|
+
tasks: true,
|
|
14
|
+
},
|
|
15
|
+
database: {
|
|
16
|
+
default: { connector: "sqlite" },
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```json [package.json]
|
|
22
|
+
{
|
|
23
|
+
"type": "module",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"dev": "nitro dev",
|
|
26
|
+
"build": "nitro build"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"nitro": "latest"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```ts [server.ts]
|
|
35
|
+
import { defineHandler } from "nitro";
|
|
36
|
+
import { useDatabase } from "nitro/database";
|
|
37
|
+
|
|
38
|
+
export default defineHandler(async () => {
|
|
39
|
+
const db = useDatabase();
|
|
40
|
+
|
|
41
|
+
// Create users table
|
|
42
|
+
await db.sql`DROP TABLE IF EXISTS users`;
|
|
43
|
+
await db.sql`CREATE TABLE IF NOT EXISTS users ("id" TEXT PRIMARY KEY, "firstName" TEXT, "lastName" TEXT, "email" TEXT)`;
|
|
44
|
+
|
|
45
|
+
// Add a new user
|
|
46
|
+
const userId = String(Math.round(Math.random() * 10_000));
|
|
47
|
+
await db.sql`INSERT INTO users VALUES (${userId}, 'John', 'Doe', '')`;
|
|
48
|
+
|
|
49
|
+
// Query for users
|
|
50
|
+
const { rows } = await db.sql`SELECT * FROM users WHERE id = ${userId}`;
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
rows,
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```json [tsconfig.json]
|
|
59
|
+
{
|
|
60
|
+
"extends": "nitro/tsconfig"
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```ts [vite.config.ts]
|
|
65
|
+
import { defineConfig } from "vite";
|
|
66
|
+
import { nitro } from "nitro/vite";
|
|
67
|
+
|
|
68
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```ts [tasks/db/migrate.ts]
|
|
72
|
+
import { defineTask } from "nitro/task";
|
|
73
|
+
import { useDatabase } from "nitro/database";
|
|
74
|
+
|
|
75
|
+
export default defineTask({
|
|
76
|
+
meta: {
|
|
77
|
+
description: "Run database migrations",
|
|
78
|
+
},
|
|
79
|
+
async run() {
|
|
80
|
+
const db = useDatabase();
|
|
81
|
+
|
|
82
|
+
console.log("Running database migrations...");
|
|
83
|
+
|
|
84
|
+
// Create users table
|
|
85
|
+
await db.sql`DROP TABLE IF EXISTS users`;
|
|
86
|
+
await db.sql`CREATE TABLE IF NOT EXISTS users ("id" TEXT PRIMARY KEY, "firstName" TEXT, "lastName" TEXT, "email" TEXT)`;
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
result: "Database migrations complete!",
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
</code-tree>
|
|
95
|
+
|
|
96
|
+
Nitro provides a built-in database layer that uses SQL template literals for safe, parameterized queries. This example creates a users table, inserts a record, and queries it back.
|
|
97
|
+
|
|
98
|
+
## Querying the Database
|
|
99
|
+
|
|
100
|
+
```ts [server.ts]
|
|
101
|
+
import { defineHandler } from "nitro";
|
|
102
|
+
import { useDatabase } from "nitro/database";
|
|
103
|
+
|
|
104
|
+
export default defineHandler(async () => {
|
|
105
|
+
const db = useDatabase();
|
|
106
|
+
|
|
107
|
+
// Create users table
|
|
108
|
+
await db.sql`DROP TABLE IF EXISTS users`;
|
|
109
|
+
await db.sql`CREATE TABLE IF NOT EXISTS users ("id" TEXT PRIMARY KEY, "firstName" TEXT, "lastName" TEXT, "email" TEXT)`;
|
|
110
|
+
|
|
111
|
+
// Add a new user
|
|
112
|
+
const userId = String(Math.round(Math.random() * 10_000));
|
|
113
|
+
await db.sql`INSERT INTO users VALUES (${userId}, 'John', 'Doe', '')`;
|
|
114
|
+
|
|
115
|
+
// Query for users
|
|
116
|
+
const { rows } = await db.sql`SELECT * FROM users WHERE id = ${userId}`;
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
rows,
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Retrieve the database instance using `useDatabase()`. The database can be queried using `db.sql`, and variables like `${userId}` are automatically escaped to prevent SQL injection.
|
|
125
|
+
|
|
126
|
+
## Running Migrations with Tasks
|
|
127
|
+
|
|
128
|
+
Nitro tasks let you run operations outside of request handlers. For database migrations, create a task file in `tasks/` and run it via the CLI. This keeps schema changes separate from your application code.
|
|
129
|
+
|
|
130
|
+
```ts [tasks/db/migrate.ts]
|
|
131
|
+
import { defineTask } from "nitro/task";
|
|
132
|
+
import { useDatabase } from "nitro/database";
|
|
133
|
+
|
|
134
|
+
export default defineTask({
|
|
135
|
+
meta: {
|
|
136
|
+
description: "Run database migrations",
|
|
137
|
+
},
|
|
138
|
+
async run() {
|
|
139
|
+
const db = useDatabase();
|
|
140
|
+
|
|
141
|
+
console.log("Running database migrations...");
|
|
142
|
+
|
|
143
|
+
// Create users table
|
|
144
|
+
await db.sql`DROP TABLE IF EXISTS users`;
|
|
145
|
+
await db.sql`CREATE TABLE IF NOT EXISTS users ("id" TEXT PRIMARY KEY, "firstName" TEXT, "lastName" TEXT, "email" TEXT)`;
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
result: "Database migrations complete!",
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Learn More
|
|
155
|
+
|
|
156
|
+
- [Database](/docs/database)
|
|
157
|
+
- [Tasks](/docs/tasks)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Elysia
|
|
2
|
+
|
|
3
|
+
> Integrate Elysia with Nitro using the server entry.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({});
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```json [package.json]
|
|
14
|
+
{
|
|
15
|
+
"type": "module",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "nitro build",
|
|
18
|
+
"dev": "nitro dev"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"elysia": "^1.4.22",
|
|
22
|
+
"nitro": "latest"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts [server.ts]
|
|
28
|
+
import { Elysia } from "elysia";
|
|
29
|
+
|
|
30
|
+
const app = new Elysia();
|
|
31
|
+
|
|
32
|
+
app.get("/", () => "Hello, Elysia with Nitro!");
|
|
33
|
+
|
|
34
|
+
export default app.compile();
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```json [tsconfig.json]
|
|
38
|
+
{
|
|
39
|
+
"extends": "nitro/tsconfig"
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```ts [vite.config.ts]
|
|
44
|
+
import { defineConfig } from "vite";
|
|
45
|
+
import { nitro } from "nitro/vite";
|
|
46
|
+
|
|
47
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
48
|
+
```
|
|
49
|
+
</code-tree>
|
|
50
|
+
|
|
51
|
+
## Server Entry
|
|
52
|
+
|
|
53
|
+
```ts [server.ts]
|
|
54
|
+
import { Elysia } from "elysia";
|
|
55
|
+
|
|
56
|
+
const app = new Elysia();
|
|
57
|
+
|
|
58
|
+
app.get("/", () => "Hello, Elysia with Nitro!");
|
|
59
|
+
|
|
60
|
+
export default app.compile();
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Nitro auto-detects `server.ts` in your project root and uses it as the server entry. The Elysia app handles all incoming requests, giving you full control over routing and middleware.
|
|
64
|
+
|
|
65
|
+
Call `app.compile()` before exporting to optimize the router for production.
|
|
66
|
+
|
|
67
|
+
## Learn More
|
|
68
|
+
|
|
69
|
+
- [Server Entry](/docs/server-entry)
|
|
70
|
+
- [Elysia Documentation](https://elysiajs.com/)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Express
|
|
2
|
+
|
|
3
|
+
> Integrate Express with Nitro using the server entry.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({});
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```json [package.json]
|
|
14
|
+
{
|
|
15
|
+
"type": "module",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "nitro build",
|
|
18
|
+
"dev": "nitro dev"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/express": "^5.0.6",
|
|
22
|
+
"express": "^5.2.1",
|
|
23
|
+
"nitro": "latest"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```ts [server.node.ts]
|
|
29
|
+
import Express from "express";
|
|
30
|
+
|
|
31
|
+
const app = Express();
|
|
32
|
+
|
|
33
|
+
app.use("/", (_req, res) => {
|
|
34
|
+
res.send("Hello from Express with Nitro!");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export default app;
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```json [tsconfig.json]
|
|
41
|
+
{
|
|
42
|
+
"extends": "nitro/tsconfig"
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```ts [vite.config.ts]
|
|
47
|
+
import { defineConfig } from "vite";
|
|
48
|
+
import { nitro } from "nitro/vite";
|
|
49
|
+
|
|
50
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
51
|
+
```
|
|
52
|
+
</code-tree>
|
|
53
|
+
|
|
54
|
+
## Server Entry
|
|
55
|
+
|
|
56
|
+
```ts [server.node.ts]
|
|
57
|
+
import Express from "express";
|
|
58
|
+
|
|
59
|
+
const app = Express();
|
|
60
|
+
|
|
61
|
+
app.use("/", (_req, res) => {
|
|
62
|
+
res.send("Hello from Express with Nitro!");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export default app;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Nitro auto-detects `server.node.ts` in your project root and uses it as the server entry. The Express app handles all incoming requests, giving you full control over routing and middleware.
|
|
69
|
+
|
|
70
|
+
<note>
|
|
71
|
+
|
|
72
|
+
The `.node.ts` suffix indicates this entry is Node.js specific and won't work in other runtimes like Cloudflare Workers or Deno.
|
|
73
|
+
</note>
|
|
74
|
+
|
|
75
|
+
## Learn More
|
|
76
|
+
|
|
77
|
+
- [Server Entry](/docs/server-entry)
|
|
78
|
+
- [Express Documentation](https://expressjs.com/)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Fastify
|
|
2
|
+
|
|
3
|
+
> Integrate Fastify with Nitro using the server entry.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({});
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```json [package.json]
|
|
14
|
+
{
|
|
15
|
+
"type": "module",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "nitro build",
|
|
18
|
+
"dev": "nitro dev"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"fastify": "^5.7.4",
|
|
22
|
+
"nitro": "latest"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts [server.node.ts]
|
|
28
|
+
import Fastify from "fastify";
|
|
29
|
+
|
|
30
|
+
const app = Fastify();
|
|
31
|
+
|
|
32
|
+
app.get("/", () => "Hello, Fastify with Nitro!");
|
|
33
|
+
|
|
34
|
+
await app.ready();
|
|
35
|
+
|
|
36
|
+
export default app.routing;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```json [tsconfig.json]
|
|
40
|
+
{
|
|
41
|
+
"extends": "nitro/tsconfig"
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```ts [vite.config.ts]
|
|
46
|
+
import { defineConfig } from "vite";
|
|
47
|
+
import { nitro } from "nitro/vite";
|
|
48
|
+
|
|
49
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
50
|
+
```
|
|
51
|
+
</code-tree>
|
|
52
|
+
|
|
53
|
+
## Server Entry
|
|
54
|
+
|
|
55
|
+
```ts [server.node.ts]
|
|
56
|
+
import Fastify from "fastify";
|
|
57
|
+
|
|
58
|
+
const app = Fastify();
|
|
59
|
+
|
|
60
|
+
app.get("/", () => "Hello, Fastify with Nitro!");
|
|
61
|
+
|
|
62
|
+
await app.ready();
|
|
63
|
+
|
|
64
|
+
export default app.routing;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Nitro auto-detects `server.node.ts` in your project root and uses it as the server entry.
|
|
68
|
+
|
|
69
|
+
Call `await app.ready()` to initialize all registered plugins before exporting. Export `app.routing` (not `app`) to provide Nitro with the request handler function.
|
|
70
|
+
|
|
71
|
+
<note>
|
|
72
|
+
|
|
73
|
+
The `.node.ts` suffix indicates this entry is Node.js specific and won't work in other runtimes like Cloudflare Workers or Deno.
|
|
74
|
+
</note>
|
|
75
|
+
|
|
76
|
+
## Learn More
|
|
77
|
+
|
|
78
|
+
- [Server Entry](/docs/server-entry)
|
|
79
|
+
- [Fastify Documentation](https://fastify.dev/)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Hello World
|
|
2
|
+
|
|
3
|
+
> Minimal Nitro server using the web standard fetch handler.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({});
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```json [package.json]
|
|
14
|
+
{
|
|
15
|
+
"type": "module",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "nitro build",
|
|
18
|
+
"dev": "nitro dev",
|
|
19
|
+
"preview": "node .output/server/index.mjs"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"nitro": "latest"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts [server.ts]
|
|
28
|
+
export default {
|
|
29
|
+
fetch(req: Request) {
|
|
30
|
+
return new Response("Nitro Works!");
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```json [tsconfig.json]
|
|
36
|
+
{
|
|
37
|
+
"extends": "nitro/tsconfig"
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```ts [vite.config.ts]
|
|
42
|
+
import { defineConfig } from "vite";
|
|
43
|
+
import { nitro } from "nitro/vite";
|
|
44
|
+
|
|
45
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
46
|
+
```
|
|
47
|
+
</code-tree>
|
|
48
|
+
|
|
49
|
+
The simplest Nitro server. Export an object with a `fetch` method that receives a standard `Request` and returns a `Response`. No frameworks, no abstractions, just the web platform.
|
|
50
|
+
|
|
51
|
+
## Server Entry
|
|
52
|
+
|
|
53
|
+
```ts [server.ts]
|
|
54
|
+
export default {
|
|
55
|
+
fetch(req: Request) {
|
|
56
|
+
return new Response("Nitro Works!");
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The `fetch` method follows the same signature as Service Workers and Cloudflare Workers. This pattern works across all deployment targets because it uses web standards.
|
|
62
|
+
|
|
63
|
+
Add the Nitro plugin to Vite and it handles the rest: dev server, hot reloading, and production builds.
|
|
64
|
+
|
|
65
|
+
## Learn More
|
|
66
|
+
|
|
67
|
+
- [Server Entry](/docs/server-entry)
|
|
68
|
+
- [Configuration](/docs/configuration)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Hono
|
|
2
|
+
|
|
3
|
+
> Integrate Hono with Nitro using the server entry.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({});
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```json [package.json]
|
|
14
|
+
{
|
|
15
|
+
"type": "module",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "nitro build",
|
|
18
|
+
"dev": "nitro dev"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"hono": "^4.11.8",
|
|
22
|
+
"nitro": "latest"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts [server.ts]
|
|
28
|
+
import { Hono } from "hono";
|
|
29
|
+
|
|
30
|
+
const app = new Hono();
|
|
31
|
+
|
|
32
|
+
app.get("/", (c) => {
|
|
33
|
+
return c.text("Hello, Hono with Nitro!");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export default app;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```json [tsconfig.json]
|
|
40
|
+
{
|
|
41
|
+
"extends": "nitro/tsconfig"
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```ts [vite.config.ts]
|
|
46
|
+
import { defineConfig } from "vite";
|
|
47
|
+
import { nitro } from "nitro/vite";
|
|
48
|
+
|
|
49
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
50
|
+
```
|
|
51
|
+
</code-tree>
|
|
52
|
+
|
|
53
|
+
## Server Entry
|
|
54
|
+
|
|
55
|
+
```ts [server.ts]
|
|
56
|
+
import { Hono } from "hono";
|
|
57
|
+
|
|
58
|
+
const app = new Hono();
|
|
59
|
+
|
|
60
|
+
app.get("/", (c) => {
|
|
61
|
+
return c.text("Hello, Hono with Nitro!");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export default app;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Nitro auto-detects `server.ts` in your project root and uses it as the server entry. The Hono app handles all incoming requests, giving you full control over routing and middleware.
|
|
68
|
+
|
|
69
|
+
Hono is cross-runtime compatible, so this server entry works across all Nitro deployment targets including Node.js, Deno, Bun, and Cloudflare Workers.
|
|
70
|
+
|
|
71
|
+
## Learn More
|
|
72
|
+
|
|
73
|
+
- [Server Entry](/docs/server-entry)
|
|
74
|
+
- [Hono Documentation](https://hono.dev/)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Import Alias
|
|
2
|
+
|
|
3
|
+
> Custom import aliases for cleaner module paths.
|
|
4
|
+
|
|
5
|
+
<code-tree>
|
|
6
|
+
|
|
7
|
+
```ts [nitro.config.ts]
|
|
8
|
+
import { defineConfig } from "nitro";
|
|
9
|
+
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
serverDir: true,
|
|
12
|
+
experimental: {
|
|
13
|
+
tsconfigPaths: true,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```json [package.json]
|
|
19
|
+
{
|
|
20
|
+
"type": "module",
|
|
21
|
+
"imports": {
|
|
22
|
+
"#server/*": "./server/*"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "nitro build",
|
|
26
|
+
"dev": "nitro dev",
|
|
27
|
+
"preview": "node .output/server/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"nitro": "latest"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```json [tsconfig.json]
|
|
36
|
+
{
|
|
37
|
+
"extends": "nitro/tsconfig",
|
|
38
|
+
"compilerOptions": {
|
|
39
|
+
"paths": {
|
|
40
|
+
"~server/*": ["./server/*"]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```ts [vite.config.ts]
|
|
47
|
+
import { defineConfig } from "vite";
|
|
48
|
+
import { nitro } from "nitro/vite";
|
|
49
|
+
|
|
50
|
+
export default defineConfig({ plugins: [nitro()] });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```ts [server/routes/index.ts]
|
|
54
|
+
import { sum } from "~server/utils/math.ts";
|
|
55
|
+
|
|
56
|
+
import { rand } from "#server/utils/math.ts";
|
|
57
|
+
|
|
58
|
+
export default () => {
|
|
59
|
+
const [a, b] = [rand(1, 10), rand(1, 10)];
|
|
60
|
+
const result = sum(a, b);
|
|
61
|
+
return `The sum of ${a} + ${b} = ${result}`;
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```ts [server/utils/math.ts]
|
|
66
|
+
export function rand(min: number, max: number): number {
|
|
67
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function sum(a: number, b: number): number {
|
|
71
|
+
return a + b;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
</code-tree>
|
|
75
|
+
|
|
76
|
+
Import aliases like `~` and `#` let you reference modules with shorter paths instead of relative imports.
|
|
77
|
+
|
|
78
|
+
## Importing Using Aliases
|
|
79
|
+
|
|
80
|
+
```ts [server/routes/index.ts]
|
|
81
|
+
import { sum } from "~server/utils/math.ts";
|
|
82
|
+
|
|
83
|
+
import { rand } from "#server/utils/math.ts";
|
|
84
|
+
|
|
85
|
+
export default () => {
|
|
86
|
+
const [a, b] = [rand(1, 10), rand(1, 10)];
|
|
87
|
+
const result = sum(a, b);
|
|
88
|
+
return `The sum of ${a} + ${b} = ${result}`;
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The route imports the `sum` function using `~server/` and `rand` using `#server/`. Both resolve to the same `server/utils/math.ts` file. The handler generates two random numbers and returns their sum.
|
|
93
|
+
|
|
94
|
+
## Configuration
|
|
95
|
+
|
|
96
|
+
Aliases can be configured in `package.json` imports field or `nitro.config.ts`.
|
|
97
|
+
|
|
98
|
+
## Learn More
|
|
99
|
+
|
|
100
|
+
- [Configuration](/docs/configuration)
|