Analog Meta-Framework for Angular
repository·beta·Indexed 25 days ago
https://github.com/analogjs/analogA fullstack meta-framework for Angular powered by Vite and Nitro, providing modern web development features such as file-based routing, hybrid SSR/SSG, and integrated API routes. The ecosystem includes @analogjs/astro-angular for rendering standalone Angular components as Astro islands, @analogjs/platform for Nx monorepo integration, and @analogjs/content for content processing with support for Shiki and Prism highlighters.
What's inside Analog
- Analog is a fullstack meta-framework designed for building applications and websites using Angular. It provides a developer experience similar to Next.JS, Nuxt, SvelteKit, and Qwik City, but is built specifically on top of the Angular ecosystem.
Overview of Analog
betaAnalog is a fullstack meta-framework for Angular. It provides a unified development experience for building Angular applications with server-side capabilities.Overview of Analog features
betaAnalog is a meta-framework for building applications and websites with Angular, providing a developer experience similar to Next.js or Nuxt. Key features include:
- Vite-powered: High-performance development and build process.
- File-based routing: Automatically defines routes based on your file structure.
- Nitro-powered: Server and deployment integrations via Nitro.
- Hybrid Rendering: Supports both Server-Side Rendering (SSR) and Static Site Generation (SSG).
- Content Support: Use Markdown as content routes.
- API/Server Routes: Integrated support for server-side logic.
- Tooling Support: Built-in support for Vitest, Storybook, Angular CLI, and Nx workspaces.
Overview of @analogjs/vite-plugin-angular-tools
beta@analogjs/vite-plugin-angular-tools provides Builders and Schematics designed to work with the@analogjs/vite-plugin-angularpackage. It helps automate and streamline the integration of Angular with Vite-based build tools in the Analog ecosystem.Understand the Astro project structure
betaAstro projects follow a specific directory convention for routing and assets:
- Routing: Astro automatically exposes
.astroor.mdfiles located insrc/pages/as routes based on their filenames. - Components: Custom components (Astro, React, Vue, Svelte, or Preact) are typically stored in
src/components/. - Static Assets: Files like images or favicons that should be served as-is are placed in the
public/directory.
Example structure:
/ ├── public/ │ └── favicon.svg ├── src/ │ ├── components/ │ │ └── Card.astro │ ├── layouts/ │ │ └── Layout.astro │ └── pages/ │ └── index.astro └── package.json- Routing: Astro automatically exposes
Core Features of Analog
betaAnalog provides several key capabilities for modern web development:
- Tooling: Built on Vite, Vitest, and Playwright.
- Server/Deployment: Powered by Nitro for server and deployment integrations.
- Routing: Supports file-based routing and using Markdown as content routes.
- Data Fetching: Supports server-side data fetching.
- API Routes: Supports creating API and server routes.
- Rendering Modes: Hybrid support for Server-Side Rendering (SSR) and Static Site Generation (SSG).
- Integrations: Works with Angular CLI, Nx workspaces, and supports using Angular components within Astro via
@analogjs/astro-angular.
Add Analog to an Nx monorepo using @analogjs/platform
betaThe@analogjs/platformpackage is the official plugin for integrating Analog into an Nx monorepo environment. It provides generators to scaffold preconfigured Analog applications within your workspace.Create a standalone Nx project with Analog
betaYou can scaffold a new, standalone Nx workspace preconfigured with Analog using the
@analogjs/platformpreset. During the setup process, you will be prompted for your application name and whether you want to include TailwindCSS. If TailwindCSS is selected, all dependencies and configurations are automatically set up.npx create-nx-workspace@latest --preset=@analogjs/platformHandle Errors in API Routes
betaBy default, uncaught errors return a
500 Internal Server Error. To return specific HTTP status codes, use thecreateErrorfunction fromh3to throw an exception.import { defineEventHandler, getRouterParam, createError } from 'h3'; export default defineEventHandler((event) => { const param = getRouterParam(event, 'id'); const id = parseInt(param ? param : ''); if (!Number.isInteger(id)) { throw createError({ statusCode: 400, statusMessage: 'ID should be an integer', }); } return `ID is ${id}`; });// routes/api/v1/[id].ts import { defineEventHandler, getRouterParam, createError } from 'h3'; export default defineEventHandler((event) => { const param = getRouterParam(event, 'id'); const id = parseInt(param ? param : ''); if (!Number.isInteger(id)) { throw createError({ statusCode: 400, statusMessage: 'ID should be an integer', }); } return `ID is ${id}`; });Configure Storybook with @analogjs/storybook-angular
betaUpdate your
.storybook/main.tsto use theStorybookConfigtype and set theframeworkname to@analogjs/storybook-angular. Ensure you remove any existingwebpackFinalconfiguration.Additionally, update your
angular.jsonorproject.jsonto use the@analogjs/storybook-angularbuilders forstorybookandbuild-storybook. Remove anywebpackspecific options and thebrowserTargetoption. Finally, add/storybook-staticto your.gitignore.import { StorybookConfig } from '@analogjs/storybook-angular'; const config: StorybookConfig = { // other config, addons, etc. framework: { name: '@analogjs/storybook-angular', options: {}, }, }; export default config;Enable Progressive Streaming SSR in Analog
betaTo enable experimental Progressive Streaming SSR, you must configure the
analogplugin in yourvite.config.tswith thestreamingexperimental flag set totrue. This allows the server to flush the document head and@deferblocks progressively, improving Time to First Byte (TTFB) and First Contentful Paint (FCP).// vite.config.ts export default defineConfig({ plugins: [analog({ experimental: { streaming: true } })], });Create API Routes
betaAPI routes are filesystem-based and are located in thesrc/server/routes/apidirectory. They are automatically exposed under the/apiprefix. UsedefineEventHandlerfromh3to define the route logic.