framework
framework copied to clipboard
An option for having separate server and client directories
Describe the feature
The current directory structure can be overwhelming for a large project. Considering that the server directory is already pretty much separate from the rest of the app, It'd be nice if we could separate those concerns at the directory level.
My proposal is a new clientDir
option similar to srcDir
.
Example if clientDir
set to client/
:
|-- client
|-- assets
|-- components
|-- composables
|-- layouts
|-- middleware
|-- pages
|-- public
|-- plugins
|-- server
|-- api
|-- middleware
|-- nuxt.config.ts
|-- package.json
the current workaround is:
export default defineNuxtConfig({
dir: {
layouts: 'client/layouts',
middleware: 'client/middleware',
public: 'client/public',
pages: 'client/pages',
},
imports: {
dirs: ['client/composables'],
},
components: {
dirs: ['client/components'],
},
tailwindcss: { cssPath: './client/assets/css/tailwind.css' }, // Module specific changes
});
Additional information
- [X] Would you be willing to help implement this feature?
- [ ] Could this feature be implemented as a module?
Final checks
- [X] Read the contribution guide.
- [X] Check existing discussions and issues.
An is nice suggestion
This would be awesome. Please can nuxt theme look into it.
Thanks for the suggestion. Since components
/layouts
/middleware
/etc are also used for server-side-rendering, moving into client/
or with clientDir
is not semantically correct.
However, i think it makes sense to make server dir configurable (currently it is hardcoded relative to srcDir). This way you can achieve this easier with two configs:
defineNuxtConfig({
srcDir: './client', // Technically only correct name _without_ ssr
serverDir: './server', // Instead of {srcDir}/server
// Alternative:
dirs: { server: './server' }
})
Maybe front-end
is a better name for that directory, serverDir
seems like a good idea to me