The core package of Photon - an unopinionated and flexible alternative to Nitro that works with any server framework and any deployment target.
npm install @photonjs/coreThe core package of Photon - an unopinionated and flexible alternative to Nitro that works with any server framework and any deployment target.
Photon Core provides the foundational functionality for building universal web applications with:
- Universal server support: Works with Hono, Express, Fastify, Elysia, H3, Hattip, and more
- Multi-platform deployment: Deploy to Netlify, Vercel, Cloudflare, VPS, or any other platform
- Vite integration: Powered by Vite's Environment API with HMR support
- Server code-splitting: Each page and API route can be deployed to separate edge workers
- TypeScript-first: Full TypeScript support with excellent DX
``bash`
npm install @photonjs/coreor
pnpm add @photonjs/coreor
yarn add @photonjs/core
Add Photon to your Vite configuration:
`ts
// vite.config.ts
import { photon } from '@photonjs/core/vite'
export default {
plugins: [
photon({
server: './src/server.ts',
entries: {
'api/users': './src/api/users.ts',
'middleware/auth': './src/middleware/auth.ts'
}
})
]
}
`
The core package accepts a configuration object with the following options:
`ts`
interface PhotonConfig {
server?: string | EntryServerPartial
entries?: Record
// Additional configuration options...
}
- ./vite - Vite plugin for Photon integration./api
- - Core API functions for managing entries and configuration./dev
- - Development server utilities./apply
- - Universal middleware application utilities./serve
- - Server creation and management utilities./errors
- - Error classes and utilities./virtual
- - TypeScript declarations for virtual modules
#### photon(config?: Photon.Config): Plugin[]
Creates the Photon Vite plugin with the specified configuration.
#### API Functions
`ts
import { api } from '@photonjs/core'
// Add a new Photon entry
api.addPhotonEntry(entry)
// Update an existing entry
api.updatePhotonEntry(id, updates)
// Get server ID with entry
api.getPhotonServerIdWithEntry(entryId)
`
`ts`
import {
PhotonError,
PhotonConfigError,
PhotonRuntimeError,
PhotonUsageError,
PhotonDependencyError,
PhotonBugError
} from '@photonjs/core'
Photon provides virtual modules that are resolved at build time:
- photon:get-middlewares:* - Access to universal middlewares for different runtimes
- Various server-specific virtual modules for different deployment targets
While this is the core package, you'll typically use it alongside server-specific adapters:
- @photonjs/express - Express.js integration@photonjs/fastify
- - Fastify integration@photonjs/hono
- - Hono integration@photonjs/h3
- - H3 integration@photonjs/elysia
- - Elysia integration@photonjs/hattip
- - Hattip integration
For deployment to specific platforms:
- @photonjs/cloudflare` - Cloudflare Workers/Pages
- More adapters coming soon for Netlify, Vercel, etc.
See the examples directory for complete working examples of Photon integration.
MIT