@edgeone/nuxt-pages
Version:
A professional deployment package that seamlessly deploys your Nuxt 3/4 applications to Tencent Cloud EdgeOne platform with optimized performance and intelligent caching.
256 lines (191 loc) ⢠6.08 kB
Markdown
# EdgeOne Nuxt Deploy
A professional deployment package that seamlessly deploys your Nuxt 3/4 applications to Tencent Cloud EdgeOne platform with optimized performance and intelligent caching.
## ⨠Features
- š **One-Click Deployment** - Automated build and deployment process for EdgeOne
- šļø **Nitro Integration** - Full compatibility with Nuxt 3's Nitro engine
- š¦ **Monorepo Support** - Optimized templates for complex project structures
- šÆ **Smart Caching** - Multi-layer caching with memory, regional blobs, and tag invalidation
- ā” **Performance Optimized** - Static asset handling, lazy loading, and OpenTelemetry tracing
- š§ **Auto Configuration** - Intelligent Nuxt config detection and modification
- š **SSR Ready** - Full server-side rendering support on EdgeOne
## š Requirements
- **Nuxt**: 3+
- **Node.js**: 18.x or higher
- **EdgeOne**: Tencent Cloud EdgeOne account
## š Quick Start
### Installation
```bash
npm install @edgeone/nuxt-pages
```
### Basic Usage
1. **Add to your build process:**
```javascript
// In your build script or CI/CD pipeline
import { onPreBuild, onBuild, onPostBuild } from '@edgeone/nuxt-pages'
const buildOptions = {
cwd: process.cwd(),
env: process.env,
meta: {},
functions: {},
constants: {
PUBLISH_DIR: 'dist'
}
}
// Execute build phases
await onPreBuild(buildOptions)
await onBuild(buildOptions)
await onPostBuild(buildOptions)
```
2. **Your Nuxt project will be automatically configured:**
The package will create or modify your `nuxt.config.ts`:
```typescript
export default defineNuxtConfig({
srcDir: 'app',
nitro: {
preset: 'node-server',
output: {
dir: '.edgeone',
publicDir: '.edgeone/assets',
serverDir: '.edgeone/server-handler',
},
},
devtools: { enabled: true },
})
```
## šļø Architecture
### Build Process
The deployment follows a three-phase approach:
1. **PreBuild Phase** (`onPreBuild`)
- Validates Nuxt version compatibility
- Configures Nitro build output
- Sets up EdgeOne-specific configurations
2. **Build Phase** (`onBuild`)
- Creates server handlers
- Generates route metadata for pages and API routes
- Patches Nitro handlers for EdgeOne compatibility
3. **PostBuild Phase** (`onPostBuild`)
- Restores original configurations
- Cleanup and optimization
### Caching Strategy
- **Memory Cache**: LRU cache for frequently accessed data
- **Regional Blobs**: Distributed storage for static assets
- **Tag Invalidation**: Smart cache invalidation based on content tags
- **Stale-While-Revalidate**: Background revalidation for optimal performance
## š Project Structure
After deployment, your project will have:
```
your-project/
āāā .edgeone/
ā āāā assets/ # Static assets
ā āāā server-handler/ # Server-side code
ā ā āāā chunks/ # Nitro chunks
ā ā āāā handler.js # EdgeOne handler
ā ā āāā index.mjs # Server entry point
ā āāā dist/ # Runtime modules
āāā app/ # Your Nuxt app (if using srcDir)
āāā nuxt.config.ts # Auto-generated/modified config
āāā package.json
```
## āļø Configuration
### Advanced Options
You can customize the deployment behavior:
```typescript
// Custom build options
const buildOptions = {
cwd: process.cwd(),
env: {
...process.env,
USE_REGIONAL_BLOBS: 'true',
NITRO_PORT: '9000'
},
meta: {
// Custom metadata
},
functions: {
// Function-specific settings
},
constants: {
PUBLISH_DIR: 'dist'
}
}
```
### Environment Variables
- `USE_REGIONAL_BLOBS`: Enable regional blob storage (default: true)
- `NITRO_PORT`: Development server port (default: 9000)
- `NITRO_PUBLIC_DIR`: Static assets directory
## šÆ Monorepo Support
For monorepo projects, the package automatically detects the structure and uses optimized templates:
```javascript
// Automatic detection of monorepo structure
// Uses nuxt-handler-monorepo.tmpl.js for complex setups
// Handles working directory changes and path resolution
```
## š§ Development
### Local Testing
The package includes a development server for local testing:
```bash
# Start development server
npm run start
```
Your Nuxt app will be available at `http://localhost:9000`
### Build Scripts
```json
{
"scripts": {
"build": "node ./tools/build.js",
"build:watch": "node ./tools/build.js --watch",
"start": "node dist/index.js",
"test": "ts-node src/test.ts"
}
}
```
## š Performance Features
- **Static Asset Optimization**: 1-year cache headers for static files
- **Lazy Loading**: Nitro app initialization on first request
- **OpenTelemetry Tracing**: Built-in performance monitoring
- **Error Handling**: Graceful fallbacks and error recovery
- **Memory Management**: Efficient memory usage with LRU caching
## šØ Compatibility
### Supported Features
- ā
Nuxt 3+
- ā
Server-Side Rendering (SSR)
- ā
Static Site Generation (SSG)
- ā
API Routes
- ā
Middleware
- ā
Plugins
- ā
Monorepo structures
### Known Limitations
- ā `@nuxt/image` module (under development)
- ā ļø Nuxt versions below 3 (compatibility in progress)
## š ļø Troubleshooting
### Common Issues
1. **Build Fails**: Ensure Nuxt version is 3+
2. **Module Conflicts**: Check for unsupported modules like `@nuxt/image`
3. **Path Issues**: Verify your project structure matches expected layout
### Debug Mode
Enable detailed logging:
```bash
DEBUG=edgeone:* npm run build
```
## š API Reference
### Core Functions
#### `onPreBuild(options: BuildOptions)`
Prepares the project for EdgeOne deployment.
#### `onBuild(options: BuildOptions)`
Executes the main build process.
#### `onPostBuild(options: BuildOptions)`
Cleanup and finalization.
### Types
```typescript
interface BuildOptions {
cwd: string
env: any
meta: any
functions: any
constants: {
PUBLISH_DIR: string
}
}
```
## š License
ISC License - see [LICENSE](LICENSE) file for details.