# Create a new application by executing:
npm create vite@latest my-app -- --template vanilla-ts
npm install @porsche-design-system/components-js
vite.config.ts file in your project directory and integrate the Porsche Design System Loader into the
<body> section of your HTML.// vite.config.ts
import { defineConfig } from 'vite';
import { getLoaderScript } from '@porsche-design-system/components-js/partials';
const transformIndexHtmlPlugin = () => {
return {
name: 'html-transform',
transformIndexHtml(html: string) {
const bodyPartials = [getLoaderScript()].join('');
return html.replace(/<\/body>/, `${bodyPartials}$&`);
},
};
};
export default defineConfig({
plugins: [transformIndexHtmlPlugin()],
});
/cn import instead, see
/* src/style.css */
+ @import '@porsche-design-system/components-js';
lightningcss polyfill for the light-dark() CSS function since it's broken.
// vite.config.ts
+ import { Features } from 'lightningcss';
export default defineConfig({
+ css: {
+ transformer: 'lightningcss',
+ // disables light-dark() polyfill of lightningcss which is broken https://github.com/porsche-design-system/porsche-design-system/issues/4257
+ lightningcss: {
+ exclude: Features.LightDark,
+ },
+ },
});
:defined.hydrated:defined
pseudo-class, scope the style to specific tags instead (e.g., :is(p-button, p-accordion, …):not(:defined)). See
/* src/style.css */
@import '@porsche-design-system/components-js';
+ :not(:defined) {
+ visibility: hidden;
+ }
<head> section of your HTML to preload fonts, icons, and component chunks.// vite.config.ts
import { defineConfig } from 'vite';
import {
getLoaderScript,
+ getComponentChunkLinks,
+ getFontLinks,
+ getIconLinks,
+ getMetaTagsAndIconLinks,
} from '@porsche-design-system/components-js/partials';
const transformIndexHtmlPlugin = () => {
return {
name: 'html-transform',
transformIndexHtml(html: string) {
+ const headPartials = [
+ // preloads fonts
+ getFontLinks(),
+ // preloads components
+ getComponentChunkLinks(),
+ // preloads icons
+ getIconLinks(),
+ // injects favicon, apple touch icons, android touch icons, etc.
+ getMetaTagsAndIconLinks({ appTitle: 'Porsche' }),
+ ].join('');
const bodyPartials = [getLoaderScript()].join('');
+ return html.replace(/<\/head>/, `${headPartials}$&`).replace(/<\/body>/, `${bodyPartials}$&`);
},
};
};
export default defineConfig({
plugins: [transformIndexHtmlPlugin()],
});
npm install tailwindcss @tailwindcss/vite
// vite.config.ts
+ import tailwindcss from '@tailwindcss/vite';
export default defineConfig({
+ plugins: [transformIndexHtmlPlugin(), tailwindcss()],
});
/* src/style.css */
@import '@porsche-design-system/components-js';
+ @import 'tailwindcss';
+ @import '@porsche-design-system/components-js/tailwindcss';
<p-wordmark></p-wordmark>) with some Tailwind CSS styles. Then, run
npm run dev and verify that the component and styles display correctly.// src/main.ts
import './style.css';
document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
<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-heading-4xl">Porsche Design System</h1>
</div>
<div class="…">…</div>
`;
