17 |
18 |
19 |
24 |
--------------------------------------------------------------------------------
/modules/blog/index.ts:
--------------------------------------------------------------------------------
1 | import { defineNuxtModule } from '@nuxt/kit'
2 | import { resolve, join } from 'path'
3 | import type { Nuxt } from '@nuxt/schema'
4 |
5 | export default defineNuxtModule({
6 | meta: {
7 | // Usually the npm package name of your module - in this case a local modal
8 | name: 'blog-module',
9 | // The key in `nuxt.config` that holds the
10 | configKey: 'blog-module',
11 | // Compatibility constraints
12 | compatibility: {
13 | // Semver version of supported nuxt versions
14 | nuxt: '^3.9.0',
15 | },
16 | },
17 | setup(options: any, nuxt: Nuxt) {
18 | // Auto register components
19 | nuxt.hook('components:dirs', (dirs) => {
20 | dirs.push({
21 | path: join(__dirname, 'components'),
22 | })
23 | })
24 |
25 | // Auto register composables
26 | nuxt.hook('imports:dirs', (dirs) => {
27 | dirs.push(resolve(__dirname, './composables'))
28 | })
29 |
30 | // Auto register pages
31 | nuxt.hook('pages:extend', (pages) => {
32 | pages.push({
33 | name: 'blog',
34 | path: '/blog',
35 | file: resolve(__dirname, './pages/blog.vue'),
36 | })
37 | })
38 | },
39 | })
40 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 🙋🏽♂️ Domain-Driven Design & Nuxt - Using Nuxt Modules to structure large Nuxt Apps
2 |
3 | #### ⚡️ Talk at NUXT NATION by Anton Reindl
4 |
5 | In my talk in 2021, I introduced Domain Driven Design and talked about structuring apps according to domain modules. I and demonstrated how to use Nuxt 2 modules to create independent submodules including Vuex modules and routes.
6 |
7 | The original Nuxt 2 example can be found in a legacy [here](https://github.com/areindl/nuxt-structure-with-modules/tree/nuxt-v2).
8 |
9 | ### 🚀 Nuxt 3
10 |
11 | I reimplemented the example of "Anton's Biketours" in Nuxt 3. This example implements a fresh Nuxt 3 with an landing page ( `pages/index.vue` ) and one domain-module module, namely the blog-module imported from `.modules/blog` . The module has its own components, composable and pages folder to better separate the domain from the rest of the app.
12 |
13 | I also recommend to look at the [documentation](https://v3.nuxtjs.org).
14 |
15 | ## Scope
16 |
17 | ```bash
18 | npm install
19 | ```
20 |
21 | ## Development
22 |
23 | Start the development server on [http://localhost:3000](http://localhost:3000)
24 |
25 | ```bash
26 | npm run dev
27 | ```
28 |
29 | ## Production
30 |
31 | Build the application for production:
32 |
33 | ```bash
34 | npm run build
35 | ```
36 |
37 | Checkout the [deployment documentation](https://v3.nuxtjs.org/docs/deployment).
38 |
39 | ### 📚 Resources
40 |
41 | * [x] [Slides of this Talk](https://github.com/areindl/nuxt-structure-with-modules/blob/c7e3ea69f3e5aa66ccefdb0089322e78ae243b51/static/slides.pdf)
42 | * [x] Blog post [Domain-Driven Design in Nuxt Apps](https://vueschool.io/articles/vuejs-tutorials/domain-driven-design-in-nuxt-apps/) by Filip Rakowski
43 | * [x] Recommended DDD-Books:
44 | + [x] Domain-Driven Design: Tackling Complexity in the Heart of Software - by Eric Evans
45 | + [x] Implementing Domain-Driven Design by Vaughn Vernon
46 | + [x] Domain-Driven Design Distilled by Vaughn Vernon
47 |
--------------------------------------------------------------------------------