unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.54k stars 476 forks source link

Customizing the auto-import path #2554

Open Ena-Heleneto opened 3 weeks ago

Ena-Heleneto commented 3 weeks ago

Describe the feature

I want to optimize the code structure, not all of it is in untils. Can this be achieved through configuration?

Additional information

MickL commented 3 weeks ago

I am not sure if I understand your question. Do you want to add other folders that are auto imported? If yes, this is from the Nuxt docs:

You can also auto-import functions exported from custom folders or third-party packages by configuring the imports section of your nuxt.config file.

Same should apply to nitro.config.ts

Ena-Heleneto commented 3 weeks ago

First of all, thank you for your reply, but I still have some questions

This is my project structure image

I want to automatically import modules in server/services

In nuxt.config.ts, I can set the frontend module path for auto-import via imports, but this is not available for backend modules

  // `stores` Frontend module path
  // `services` Backend module path
  // I tried this way of writing, and it didn't work either.  dirs: ['stores', 'server/services'],
  imports: {
    imports: [
      { name: 'consola', from: 'consola' },
      { name: '*', from: 'echarts', as: 'eCharts' },
      { name: '*', from: 'bpmn-js', as: 'bpmn' },
      { name: '*', from: 'esdk-obs-nodejs', as: 'obs' },
    ],
    dirs: ['stores', 'services'],
  },

Do I need to configure it separately in nitro?

Thanks

Ena-Heleneto commented 2 weeks ago

Hello,Can someone help me?