UNPKG

@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
# 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.