Skip to content

Commit

Permalink
feat(pie-docs): DSW-000 add nuxt 3 integration guide to docs (#2066)
Browse files Browse the repository at this point in the history
* feat(pie-docs): DSW-000 add nuxt 3 integration guide to docs

* add test route for new page

* update overview page
  • Loading branch information
jamieomaguire authored Nov 15, 2024
1 parent 217e9cd commit a938db1
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-socks-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pie-docs": minor
---

[Added] - Nuxt3 integration guide to docs site
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
eleventyNavigation:
key: NextJS 14 Integration
parent: engineers-web-components
order: 2
order: 3
---

## Installation
Expand All @@ -16,6 +16,7 @@ And the following third party dependencies:
```bash
yarn add @lit-labs/nextjs @lit/react
```
---

## Setup

Expand Down Expand Up @@ -51,6 +52,8 @@ const nextConfig = {
module.exports = withLitSSR(nextConfig);
```

---

## Usage

{% notification {
Expand Down Expand Up @@ -79,6 +82,11 @@ export default function SomeComponent() {
}
```

{% notification {
type: "information",
message: "Check individual component `code` pages on this website to see how to use them specifically in your application. Such as [PIE Button](/components/button/code/)."
} %}

You should now be able to use any components you need in your NextJS application!

Please reach out to us if you have any troubles or spot any errors in our guide.
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
eleventyNavigation:
key: Nuxt 3 Integration
parent: engineers-web-components
order: 2
---

## Installation
Please install the following JET dependencies (examples use `yarn` but feel free to use `npm` if preferred):

```bash
yarn add @justeattakeaway/pie-css @justeattakeaway/pie-webc @justeattakeaway/pie-icons-webc
```

And the following third party dependencies:
```bash
yarn add nuxt-ssr-lit
```

## Setup

### CSS and Design Token variables
You should add [@justeattakeaway/pie-css](https://www.npmjs.com/package/@justeattakeaway/pie-css) into your Nuxt config file (or wherever you prefer) so that the variables it provides are globally available (some of these variables are used by the component styles):

```js
// Example Nuxt Config - most of the properties removed for demonstration.
export default defineNuxtConfig({
css: ['@justeattakeaway/pie-css'],
});
```

For more information on `pie-css` please take a look at the package [readme](https://github.com/justeattakeaway/pie/tree/main/packages/tools/pie-css)

### Typography
We have a [dedicated page](/foundations/typography/code/) which explains how to set up typography. In short, you need to install the JET fonts and set up the appropriate `font-face` CSS code.

### Nuxt config

To get our components working, ensure you are applying the following rules to your `nuxt.config.ts` file:

```ts
export default defineNuxtConfig({
ssr: true,

nitro: {
moduleSideEffects: [
'@justeattakeaway/pie-icons-webc',
'@justeattakeaway/pie-webc',
],
},

modules: [['nuxt-ssr-lit', { litElementPrefix: ['pie-', 'icon-'] }]],

imports: {
transform: {
exclude: [/\bpie-\b/, /\bicon-\b/],
},
},

css: ['@justeattakeaway/pie-css'],
devtools: { enabled: true },

devServer: {
port: 3002,
},

compatibilityDate: '2024-07-23',
});
```
### Nuxt Configuration Breakdown

#### 1. **Server-Side Rendering**
- **`ssr: true`**
Enables **Server-Side Rendering (SSR)** for improved SEO and faster initial page loads by rendering pages on the server.

#### 2. **Nitro Configuration**
- **`moduleSideEffects`**
Includes the following modules during the build to ensure side effects like custom element registration:
- `@justeattakeaway/pie-icons-webc`
- `@justeattakeaway/pie-webc`

#### 3. **Modules**
- Adds the **`nuxt-ssr-lit`** module to enable SSR compatibility for Lit web components.
- **`litElementPrefix`** specifies the prefixes for custom elements to be treated as Lit elements:
- `pie-`
- `icon-`

#### 4. **Imports**
- **`imports.transform.exclude`**
Prevents Nuxt from automatically transforming imports matching these patterns:
- `pie-`
- `icon-`

#### 5. **Global CSS**
- Includes global styles from the `@justeattakeaway/pie-css` package for styling custom components.

#### 6. **Compatibility Date**
- **`compatibilityDate: '2024-07-23'`**
Ensures behaviour aligns with Nuxt's functionality as of the specified date, preventing breaking changes introduced after this date.

---

## Usage

It is recommended to import all components from [@justeattakeaway/pie-webc](https://www.npmjs.com/package/@justeattakeaway/pie-webc).

In your components, you should be able to render components like so:

```html
<script setup>
// No need to destructure any imports - just directly import the js file
import '@justeattakeaway/pie-webc/components/button.js';
import '@justeattakeaway/pie-icons-webc/dist/IconCamera.js';
</script>

<template>
<div>
<pie-button size="small-productive" iconPlacement="leading">
<icon-camera slot="icon"></icon-camera>
hello, world
</pie-button>
</div>
</template>
```

{% notification {
type: "information",
message: "Check individual component \`code\` pages on this website to see how to use them specifically in your application. Such as [PIE Button](/components/button/code/)."
} %}

You should now be able to use any components you need in your Nuxt application!

Please reach out to us if you have any troubles or spot any errors in our guide.
12 changes: 6 additions & 6 deletions apps/pie-docs/src/engineers/web-components/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ ___

For every framework, you can start with our [Prerequisites Guide](https://github.com/justeattakeaway/pie/wiki/Getting-started-with-PIE-Web-Components).

For specific framework versions, please follow these guides:
### Integration Guides
For integrating our components with specific frameworks, please follow these guides:

[Vue 3 Integration Guide](https://github.com/justeattakeaway/pie/wiki/PIE-Web-Components-%E2%80%90-Vue-Integration-Guide)
- [Nuxt 3](/engineers/web-components/integration-guides/nuxt-3/)

[Nuxt 3 Integration Guide](https://github.com/justeattakeaway/pie/wiki/PIE-Web-Components-%E2%80%90-Nuxt-3)
- [NextJS 14](/engineers/web-components/integration-guides/nextjs-14/)

[Vue & Nuxt ‐ Known gotchas](https://github.com/justeattakeaway/pie/wiki/Vue-Nuxt-%E2%80%90-Known-gotchas)

[NextJS 14](/engineers/web-components/nextjs-14-integration/)
### Other guides
- [Vue & Nuxt ‐ Known gotchas](https://github.com/justeattakeaway/pie/wiki/Vue-Nuxt-%E2%80%90-Known-gotchas)

For existing users, you may be interested in our [Migration guide of Web Components to Lit 3](https://github.com/justeattakeaway/pie/wiki/PIE-Web-Components-%E2%80%90-Nuxt-2---Next-10---Vue-2-Integration). This guide also details some specific configurations for React, Next and Vue2.

Expand Down
3 changes: 2 additions & 1 deletion apps/pie-docs/test/snapshots/expected-routes.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"engineers/guidelines",
"engineers/guidelines/browser-support",
"engineers/web-components",
"engineers/web-components/nextjs-14-integration",
"engineers/web-components/integration-guides/nextjs-14",
"engineers/web-components/integration-guides/nuxt-3",
"foundations",
"foundations/colour",
"foundations/colour/tokens/alias/dark",
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5063,7 +5063,7 @@ __metadata:
languageName: unknown
linkType: soft

"@justeattakeaway/pie-monorepo-utils@0.0.0, @justeattakeaway/pie-monorepo-utils@workspace:packages/tools/pie-monorepo-utils":
"@justeattakeaway/pie-monorepo-utils@0.1.0, @justeattakeaway/pie-monorepo-utils@workspace:packages/tools/pie-monorepo-utils":
version: 0.0.0-use.local
resolution: "@justeattakeaway/pie-monorepo-utils@workspace:packages/tools/pie-monorepo-utils"
languageName: unknown
Expand Down Expand Up @@ -23030,7 +23030,7 @@ __metadata:
"@justeattakeaway/browserslist-config-pie": 0.2.0
"@justeattakeaway/pie-css": 0.13.1
"@justeattakeaway/pie-icons": 5.2.0
"@justeattakeaway/pie-monorepo-utils": 0.0.0
"@justeattakeaway/pie-monorepo-utils": 0.1.0
"@types/markdown-it": 13.0.2
eleventy-plugin-rev: 1.1.1
eleventy-plugin-toc: 1.1.5
Expand Down Expand Up @@ -23136,7 +23136,7 @@ __metadata:
"@justeattakeaway/pie-link": 1.0.0
"@justeattakeaway/pie-lottie-player": 0.0.5
"@justeattakeaway/pie-modal": 1.0.0
"@justeattakeaway/pie-monorepo-utils": 0.0.0
"@justeattakeaway/pie-monorepo-utils": 0.1.0
"@justeattakeaway/pie-notification": 0.12.6
"@justeattakeaway/pie-radio": 0.5.0
"@justeattakeaway/pie-radio-group": 0.3.0
Expand Down

0 comments on commit a938db1

Please sign in to comment.