Angular
Table of Contents
Quick start#
To build an Angular application using the Porsche Design System, follow these steps.
This guide is based on the following dependencies:
@angular/*@20tailwindcss@4@porsche-design-system/components-angular@3
npm install -g @angular/cli
ng new my-app
✔ Do you want to create a 'zoneless' application without zone.js (Developer Preview)? "Yes"
✔ Which stylesheet format would you like to use? "CSS"
✔ Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? "No"
You're all set! Start building your own application now.
Integration#
Step 1
Install the Porsche Design System within your project directory.
npm install @porsche-design-system/components-angular
Step 2
Add the PorscheDesignSystemModule
to the imports array of your @Component
or @NgModule
declaration.
import { Component, signal } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { PorscheDesignSystemModule } from '@porsche-design-system/components-angular';
@Component({
selector: 'app-root',
imports: [RouterOutlet, PorscheDesignSystemModule],
templateUrl: './app.html',
styleUrl: './app.css',
})
export class App {
protected readonly title = signal('angular');
}
Step 3 (recommended)
To boost your web application's performance and minimize issues like FOUC (Flash of Unstyled Content) and FOUT (Flash of
Unstyled Text), you can integrate Partials from the Porsche Design System into the <head>
section of your HTML.
Install
@angular-builders/custom-webpack
within your project directory.
npm install @angular-builders/custom-webpack --save-dev
Configure the angular.json
.
"architect": {
"build": {
- "builder": "@angular/build:application",
+ "builder": "@angular-builders/custom-webpack:browser",
"options": {
- "browser": "src/main.ts",
+ "indexTransform": "./index-html-transform.js",
+ "outputPath": "./dist",
+ "index": "src/index.html",
+ "main": "src/main.ts",
}
}
"serve": {
- "builder": "@angular/build:dev-server",
+ "builder": "@angular-builders/custom-webpack:dev-server",
Create a index-html-transform.js
file in your project root directory.
const partials = require('@porsche-design-system/components-angular/partials');
module.exports = (_, html) => {
const headPartials = [
partials.getInitialStyles(),
partials.getFontFaceStyles(),
partials.getFontLinks(),
partials.getComponentChunkLinks(),
partials.getIconLinks(),
partials.getMetaTagsAndIconLinks({ appTitle: 'Porsche' }),
].join('');
return html.replace(/<\/head>/, `${headPartials}$&`);
};
Step 4 (recommended)
Setting up Tailwind CSS with the Porsche Design System
Tailwind CSS Theme allows you to leverage a utility-first CSS framework while maintaining
seamless styling consistency with Porsche's design principles. This integration enables you to use the provided
Patterns and Templates, all written in Tailwind CSS, to build your application quickly and
efficiently.
Install Tailwind CSS within your project directory.
npm install tailwindcss @tailwindcss/postcss postcss
Create a .postcssrc.json
file in your project root directory.
{
"plugins": {
"@tailwindcss/postcss": {}
}
}
Import Tailwind CSS and the Porsche Design System Tailwind CSS Theme.
@import 'tailwindcss';
@import '@porsche-design-system/components-react/tailwindcss';
Step 5
Add a Porsche Design System component (e.g., <p-wordmark></p-wordmark>
) with some Tailwind CSS styles. Then, run
npm run start
and verify that the component and styles display correctly.
<div class="grid justify-items-center gap-fluid-md m-static-lg p-fluid-lg bg-surface rounded-lg">
<p-wordmark></p-wordmark>
<h1 class="prose-display-md">Porsche Design System</h1>
</div>
<div class="…">…</div>