@analogjs/astro-angular
Astro is a modern web framework designed for building fast, content-focused websites, compatible with all major frontend frameworks. Though primarily a static site generation (SSG) tool, it can also integrate dynamic components called "islands", which support partial hydration.
This package allows rendering Angular components as islands in Astro.
Setup
Using the Astro CLI
Use the astro add
command to install the integration
Using npm:
npx astro add @analogjs/astro-angular
Using pnpm:
pnpm astro add @analogjs/astro-angular
Using yarn:
yarn astro add @analogjs/astro-angular
This command:
- Installs the
@analogjs/astro-angular
package. - Adds the
@analogjs/astro-angular
integration to theastro.config.mjs
file. - Installs the necessary dependencies to render Angular components on the server and client, and common Angular dependencies, such as
@angular/common
.
Setting up the TypeScript config
The integration needs a tsconfig.app.json
at the root of the project for compilation.
Create a tsconfig.app.json
in the root of the project.
{
"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"]
}
Go to Defining A Component to set up an Angular component to use in an Astro component.
Manual Installation
The integration can also be installed manually
Install the Astro Integration
yarn add @analogjs/astro-angular
Install the necessary Angular dependencies
yarn add @angular-devkit/build-angular @angular/{animations,common,compiler-cli,compiler,core,language-service,forms,platform-browser,platform-browser-dynamic,platform-server} rxjs zone.js tslib
Adding the integration
Add the integration to the astro.config.mjs
import { defineConfig } from 'astro/config';
import angular from '@analogjs/astro-angular';
export default defineConfig({
integrations: [angular()],
});
Go to Defining A Component
Configuration
Configure Vite Angular Plugin
Provide an option object to configure the @analogjs/vite-plugin-angular
powering this plugin.
import { defineConfig } from 'astro/config';
import angular from '@analogjs/astro-angular';
export default defineConfig({
integrations: [
angular({
vite: {
inlineStylesExtension: 'scss|sass|less',
},
}),
],
});