# Create a new application by executing:
npm create vite@latest my-app -- --template react-ts
npm install @porsche-design-system/components-react
<PorscheDesignSystemProvider />.// src/main.tsx
+ import { PorscheDesignSystemProvider } from '@porsche-design-system/components-react';
createRoot(document.getElementById('root')!).render(
<StrictMode>
+ <PorscheDesignSystemProvider>
<App />
+ </PorscheDesignSystemProvider>
</StrictMode>
);
/cn import instead, see
/* src/index.css */
+ @import '@porsche-design-system/components-react';
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/index.css */
@import '@porsche-design-system/components-react';
+ :not(:defined) {
+ visibility: hidden;
+ }
<head> section of your HTML to preload fonts, icons, and component chunks.// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
+ import {
+ getComponentChunkLinks,
+ getFontLinks,
+ getIconLinks,
+ getMetaTagsAndIconLinks,
+ } from '@porsche-design-system/components-react/partials';
+ const transformIndexHtmlPlugin = () => {
+ return {
+ name: 'html-transform',
+ transformIndexHtml(html: string) {
+ const headPartials = [
+ // preloads fonts
+ getFontLinks(),
+ // preloads icons
+ getIconLinks(),
+ // preloads components
+ getComponentChunkLinks(),
+ // injects favicon, apple touch icons, android touch icons, etc.
+ getMetaTagsAndIconLinks({ appTitle: 'Porsche' }),
+ ].join('');
+
+ return html.replace(/<\/head>/, `${headPartials}$&`);
+ },
+ };
+ };
export default defineConfig({
+ plugins: [react(), transformIndexHtmlPlugin()],
});
npm install tailwindcss @tailwindcss/vite
// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
+ import tailwindcss from '@tailwindcss/vite';
export default defineConfig({
+ plugins: [react(), transformIndexHtmlPlugin(), tailwindcss()],
});
/* src/index.css */
@import '@porsche-design-system/components-react';
+ @import 'tailwindcss';
+ @import '@porsche-design-system/components-react/tailwindcss';
<PWordmark />) with some Tailwind CSS styles. Then, run npm run dev and
verify that the component and styles display correctly.// src/App.tsx
import { PWordmark } from '@porsche-design-system/components-react';
export default function Home() {
return (
<>
<div className="grid justify-items-center gap-fluid-md m-static-lg p-fluid-lg bg-surface rounded-lg">
<PWordmark />
<h1 className="prose-heading-4xl">Porsche Design System</h1>
</div>
<div className="…">…</div>
</>
);
}
