Background
When the project structure grows, sometimes it is not convenient to use a flat directory structure or keep everything in a single repo.
Why?
- A simple way to split big projects into separate parts with separate business logic
- We already have
srcDir implemented in Nuxt. This feature needs a small refactor effort and does not makes core complicated.
Proposed Solution
One can structure a project like this:
├── shop
| ├── components
| | └── nav.vue
| ├── layouts
| | └── admin.vue
| ├── middleware
| | └── admin.js
| ├── pages
| | └── shop
| | └── index.vue
| └── store
| └── admin.js
├── nuxt.config.js
├── package.json
├── pages
| └── index.vue
└── store
└── public.js
The shop/ dir should basically follow the same standard nuxt directory structure. Builder module combines all children app to the main one. And also creates aliases so components inside admin can be required using:
import Nav from '~shop/components/nav
For registering admin app, it should be registered inside nuxt.config. (Items can be npm packages or local dirs)
export default {
apps: [
'~/shop'
]
}
Limitations
These are problems with current POC. We can progressively enhance this functionality and workaround these limitations.
- Currently, store and middleware cannot be supported because
srcDir is hardcoded in vue-app templates
- There is no namespace support. (adding
admin/ prefix to store modules and pages) -- children will be registered with the same namespace.
- Just like the main project, child app files are not lodash templates. We can add a
template flag to support and copy the template child apps to the .nuxt
Background
When the project structure grows, sometimes it is not convenient to use a flat directory structure or keep everything in a single repo.
Why?
srcDirimplemented in Nuxt. This feature needs a small refactor effort and does not makes core complicated.Proposed Solution
One can structure a project like this:
The
shop/dir should basically follow the same standard nuxt directory structure. Builder module combines all children app to the main one. And also creates aliases so components inside admin can be required using:For registering
adminapp, it should be registered insidenuxt.config. (Items can be npm packages or local dirs)Limitations
These are problems with current POC. We can progressively enhance this functionality and workaround these limitations.
srcDiris hardcoded invue-apptemplatesadmin/prefix to store modules and pages) -- children will be registered with the same namespace.templateflag to support and copy the template child apps to the.nuxt