framework icon indicating copy to clipboard operation
framework copied to clipboard

An option for having separate server and client directories

Open mahdiboomeri opened this issue 2 years ago • 4 comments

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

mahdiboomeri avatar Sep 17 '22 21:09 mahdiboomeri

An is nice suggestion

HomWang avatar Sep 18 '22 03:09 HomWang

This would be awesome. Please can nuxt theme look into it.

therealokoro avatar Sep 18 '22 09:09 therealokoro

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' }
})

pi0 avatar Sep 19 '22 10:09 pi0

Maybe front-end is a better name for that directory, serverDir seems like a good idea to me

mahdiboomeri avatar Sep 19 '22 11:09 mahdiboomeri