Skip to content

Commit

Permalink
feat: use virtual filesystem for templates (#292)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Roe <daniel@roe.dev>
  • Loading branch information
pi0 and danielroe authored Jul 15, 2021
1 parent b9a7033 commit b0a9bd2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function build (nitroContext: NitroContext) {
const htmlSrc = resolve(nitroContext._nuxt.buildDir, `views/${{ 2: 'app', 3: 'document' }[2]}.template.html`)
const htmlTemplate = { src: htmlSrc, contents: '', dst: '', compiled: '' }
htmlTemplate.dst = htmlTemplate.src.replace(/.html$/, '.mjs').replace('app.', 'document.')
htmlTemplate.contents = await readFile(htmlTemplate.src, 'utf-8')
htmlTemplate.contents = nitroContext.vfs[htmlTemplate.src] || await readFile(htmlTemplate.src, 'utf-8')
await nitroContext._internal.hooks.callHook('nitro:document', htmlTemplate)
htmlTemplate.compiled = 'export default ' + serializeTemplate(htmlTemplate.contents)
await writeFile(htmlTemplate.dst, htmlTemplate.compiled)
Expand Down
2 changes: 2 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface NitroContext {
nuxtHooks: configHooksT
ignore: string[]
env: Preset
vfs: Record<string, string>
output: {
dir: string
serverDir: string
Expand Down Expand Up @@ -82,6 +83,7 @@ export function getNitroContext (nuxtOptions: NuxtOptions, input: NitroInput): N
scannedMiddleware: [],
ignore: [],
env: {},
vfs: {},
hooks: {},
nuxtHooks: {},
output: {
Expand Down

0 comments on commit b0a9bd2

Please sign in to comment.