Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added example for Nuxt3 #1140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/nuxt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Nuxt dev/build outputs
.output
.nuxt
.nitro
.cache
dist

# Node dependencies
node_modules

# Logs
logs
*.log

# Misc
.DS_Store
.fleet
.idea

# Local env files
.env.*
!.env.example
46 changes: 46 additions & 0 deletions examples/nuxt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Nuxt 3 Vanilla Extract Example

## Setup

First at the top of the vanilla-extract repo.
Make sure to install the dependencies:

```bash
# pnpm
pnpm install
```

Next at the top directory of the vanilla-extract repo we then need to build the bundles.
```bash
pnpm build
```

Next move to the nuxt example directory
```bash
cd examples/nuxt
```

## Development Server

Start the development server on http://localhost:3000

```bash
pnpm dev
```

## Production

Build the application for production:

```bash
# builds the site
pnpm build
# or pre-renders the site for static hosting
pnpm generate
```

Locally preview production build:

```bash
pnpm preview
```
7 changes: 7 additions & 0 deletions examples/nuxt/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</div>
</template>
14 changes: 14 additions & 0 deletions examples/nuxt/components/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script setup lang="ts">
import { externalStyle } from './HelloWorld.vue.css'
</script>

<template>
<h1 :class="externalStyle">using class binding</h1>
<span class="inlineStyle">using actual class</span>
</template>

<style scoped>
.inlineStyle {
font-weight: bold;
}
</style>
5 changes: 5 additions & 0 deletions examples/nuxt/components/HelloWorld.vue.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { style } from '@vanilla-extract/css'

export const externalStyle = style({
color: 'red'
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is as barebones as it gets. How do you feel about showing at least a few more of the basic features, like themes, vars, variants and maybe dynamic variables?

16 changes: 16 additions & 0 deletions examples/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineNuxtConfig } from 'nuxt/config'
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin'

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
telemetry: false,
vite: {
plugins: [
vanillaExtractPlugin({})
],
},
// Note currently server side rendering seems to break hmr (hot module reloading) with Nuxt
// One workaround is to instead bundle the vue components into a seperate vite built library
// Or disable SSR while developing components
ssr: false,
Comment on lines +12 to +15
Copy link
Collaborator

@graup graup Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about linking to the issue https://github.com/vanilla-extract-css/vanilla-extract/issues/1118

})
19 changes: 19 additions & 0 deletions examples/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "vanilla-extract-example-nuxt",
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"devDependencies": {
"@nuxt/ui-templates": "^1.2.0",
"@vanilla-extract/css": "workspace:*",
"@vanilla-extract/vite-plugin": "workspace:*",
"nuxt": "^3.6.3",
"vue": "^3.3.4",
"vue-router": "^4.2.4"
}
}
9 changes: 9 additions & 0 deletions examples/nuxt/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import HelloWorld from '../components/HelloWorld.vue'

export default defineComponent(() => {
return () => (
<>
<HelloWorld />
</>
)
})
Binary file added examples/nuxt/public/favicon.ico
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/nuxt/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
Loading