Skip to content

feat(kit,schema): add addServerTemplate utility#29320

Merged
danielroe merged 1 commit into
mainfrom
feat/server-template
Oct 8, 2024
Merged

feat(kit,schema): add addServerTemplate utility#29320
danielroe merged 1 commit into
mainfrom
feat/server-template

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

#29302

📚 Description

This adds a addServerTemplate utility to more easily wrap adding a template for a nitro virtual file.

@danielroe danielroe added ✨ enhancement New feature or improvement to existing functionality nitro Nitro server engine integration kit Nuxt Kit module utilities 🍰 p2-nice-to-have Nice to have, not blocking labels Oct 8, 2024
@danielroe danielroe requested a review from pi0 October 8, 2024 10:05
@danielroe danielroe self-assigned this Oct 8, 2024
@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions Bot added the 3.x label Oct 8, 2024

@pi0 pi0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and safe using nitro virtual options.

@danielroe danielroe merged commit e553032 into main Oct 8, 2024
@danielroe danielroe deleted the feat/server-template branch October 8, 2024 14:58
@github-actions github-actions Bot mentioned this pull request Oct 8, 2024
@github-actions github-actions Bot mentioned this pull request Oct 9, 2024
3 tasks
@sandros94

Copy link
Copy Markdown
Member

Sorry to disturb, but I'm not able to understand how to access virtual files in runtime (within a server route/util)

@danielroe

Copy link
Copy Markdown
Member Author

Once you are on v3.15 (not released), you would do in a module:

import { addServerTemplate, defineNuxtModule } from 'nuxt/kit'

export default defineNuxtModule({
  setup () {
    addServerTemplate({
      filename: '#my-module/test.js',
      getContents () {
        return 'export const test = 123'
      },
    })
  },
})

... and then in a runtime file:

import { test } from '#my-module/test.js'

export default eventHandler(() => {
  return test
})

@sandros94

Copy link
Copy Markdown
Member

Once you are on v3.15

Ah! So there is still something else missing other than the addServerTemplate in v3.14

@Pentadome

Copy link
Copy Markdown

does this support typescript?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x ✨ enhancement New feature or improvement to existing functionality kit Nuxt Kit module utilities nitro Nitro server engine integration 🍰 p2-nice-to-have Nice to have, not blocking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants