@analogjs/astro-angular
Astro 是一个现代 Web 框架,专为构建快速、内容为中心的网站而设计,兼容所有主流前端框架。虽然它主要是一个静态站点生成 (SSG) 工具,但它也可以集成称为 "islands" 的动态组件,这些组件支持部分 hydration。
此包允许在 Astro 中将 Angular 组件作为 islands 渲染。
设置
使用 Astro CLI
使用 astro add 命令安装集成
使用 npm:
npx astro add @analogjs/astro-angular
使用 pnpm:
pnpm astro add @analogjs/astro-angular
使用 yarn:
yarn astro add @analogjs/astro-angular
此命令将:
- 安装
@analogjs/astro-angular包。 - 将
@analogjs/astro-angular集成添加到astro.config.mjs文件中。 - 安装在服务端和客户端渲染 Angular 组件所需的依赖项,以及常见的 Angular 依赖项,例如
@angular/common。
设置 TypeScript 配置
该集成需要在项目根目录下有一个 tsconfig.app.json 用于编译。
在项目根目录下创建一个 tsconfig.app.json。
{
"extends": "./tsconfig.json",
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"noEmit": false,
"target": "es2020",
"module": "es2020",
"lib": ["es2020", "dom"],
"skipLibCheck": true
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true,
"allowJs": false
},
"files": [],
"include": ["src/**/*.ts", "src/**/*.tsx"]
}
前往 定义组件 以设置要在 Astro 组件中使用的 Angular 组件。