Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

learning: nitro utils #82

Open
Drew-Macgibbon opened this issue Jul 2, 2023 · 2 comments
Open

learning: nitro utils #82

Drew-Macgibbon opened this issue Jul 2, 2023 · 2 comments
Assignees
Labels
🗣️ discuss further discussion is required

Comments

@Drew-Macgibbon
Copy link
Contributor

This is a running thread of my findings about nitro utils, add them to server/utils in Nuxt 3

@Drew-Macgibbon Drew-Macgibbon self-assigned this Jul 2, 2023
@Drew-Macgibbon Drew-Macgibbon added the 🗣️ discuss further discussion is required label Jul 2, 2023
@Drew-Macgibbon
Copy link
Contributor Author

Drew-Macgibbon commented Jul 2, 2023

functions inside the server/utils folder are auto-imported and usable in api/middleware/util` folders.

Util Test:

logger is a util function from another file, auto-imported

export const namedExport = () => {
  logger.info('I am a named export')
}

export default () => {
  logger.info('I am a default export from the same file')
}

Api Route:

export default defineEventHandler(() => {
  logger.info('testing util exports')
  try {
    namedExport()
    fileNameDefault()
  } catch (err: any) {
    logger.error(err)
  }
})

output:

2023-07-02 10:20:29:2029 info: testing util exports                                                                                                                                        
2023-07-02 10:20:29:2029 info: I am a named export                                                                                                                                                                                                                                                               
2023-07-02 10:20:29:2029 info: I am a default export from the same file

@Drew-Macgibbon
Copy link
Contributor Author

Drew-Macgibbon commented Aug 7, 2023

it appears that auto-imports don't work above 1 level of nesting. eg: utils/dir1/functionWillAutoImport but utils/dir1/dir2/functionWillNotAutoImport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗣️ discuss further discussion is required
Projects
None yet
Development

No branches or pull requests

1 participant