|
| 1 | +# Nuxt Generator |
| 2 | + |
| 3 | +Bootstrap a [Nuxt 3](https://nuxt.com/) application: |
| 4 | + |
| 5 | +```console |
| 6 | +npx nuxi init my-app |
| 7 | +cd my-app |
| 8 | +``` |
| 9 | + |
| 10 | +Install the required dependencies: |
| 11 | + |
| 12 | +```console |
| 13 | +yarn add dayjs @pinia/nuxt qs @types/qs |
| 14 | +``` |
| 15 | + |
| 16 | +To generate the code you need for a given resource, run the following command: |
| 17 | + |
| 18 | +```console |
| 19 | +yarn create @api-platform/client https://demo.api-platform.com . --generator nuxt --resource foo |
| 20 | +``` |
| 21 | + |
| 22 | +Replace the URL with the entrypoint of your Hydra-enabled API. You can also use an OpenAPI documentation with `https://demo.api-platform.com/docs.json` and `-f openapi3`. |
| 23 | + |
| 24 | +Omit the resource flag to generate files for all resource types exposed by the API. |
| 25 | + |
| 26 | +Add Pinia module in `nuxt.config.ts`: |
| 27 | + |
| 28 | +```typescript |
| 29 | +// https://nuxt.com/docs/api/configuration/nuxt-config |
| 30 | +export default defineNuxtConfig({ |
| 31 | + // ... |
| 32 | + modules: ["@pinia/nuxt"], |
| 33 | + // ... |
| 34 | +}); |
| 35 | +``` |
| 36 | + |
| 37 | +Delete `app.vue` as it will prevent Nuxt router to work correctly. |
| 38 | + |
| 39 | +Optionally, install Tailwind to get an app that looks good: |
| 40 | + |
| 41 | +```console |
| 42 | +yarn add -D tailwindcss postcss autoprefixer |
| 43 | +yarn tailwindcss init -p |
| 44 | +``` |
| 45 | + |
| 46 | +Add this code in `nuxt.config.ts`: |
| 47 | + |
| 48 | +```typescript |
| 49 | +// https://nuxt.com/docs/api/configuration/nuxt-config |
| 50 | +export default defineNuxtConfig({ |
| 51 | + // ... |
| 52 | + css: ['~/assets/css/main.css'], |
| 53 | + postcss: { |
| 54 | + plugins: { |
| 55 | + tailwindcss: {}, |
| 56 | + autoprefixer: {}, |
| 57 | + }, |
| 58 | + }, |
| 59 | + // ... |
| 60 | +}); |
| 61 | +``` |
| 62 | + |
| 63 | +And this code in `tailwind.config.js`: |
| 64 | + |
| 65 | +```javascript |
| 66 | +/** @type {import('tailwindcss').Config} */ |
| 67 | +module.exports = { |
| 68 | + content: [ |
| 69 | + "./components/**/*.{js,vue,ts}", |
| 70 | + "./layouts/**/*.vue", |
| 71 | + "./pages/**/*.vue", |
| 72 | + "./plugins/**/*.{js,ts}", |
| 73 | + "./nuxt.config.{js,ts}", |
| 74 | + "./app.vue", |
| 75 | + ], |
| 76 | + theme: { |
| 77 | + extend: {}, |
| 78 | + }, |
| 79 | + plugins: [], |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +Create the file `assets/css/main.css` and add this code in it: |
| 84 | + |
| 85 | +```css |
| 86 | +@tailwind base; |
| 87 | +@tailwind components; |
| 88 | +@tailwind utilities; |
| 89 | +``` |
| 90 | + |
| 91 | +You can launch the server with: |
| 92 | + |
| 93 | +```console |
| 94 | +yarn dev -o |
| 95 | +```` |
| 96 | + |
| 97 | +Go to `https://localhost:3000/books/` to start using your app. |
| 98 | + |
| 99 | +## Screenshots |
| 100 | + |
| 101 | + |
| 102 | + |
0 commit comments