Skip to content

Commit

Permalink
refactor(nuxt3): use the @nuxt/kit template utilites (nuxt#1908)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Nov 15, 2021
1 parent a7eacfe commit c53b6a5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 29 deletions.
19 changes: 0 additions & 19 deletions packages/nuxt3/src/core/template.utils.ts

This file was deleted.

12 changes: 5 additions & 7 deletions packages/nuxt3/src/core/templates.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import { templateUtils } from '@nuxt/kit'
import type { Nuxt, NuxtApp } from '@nuxt/kit'

import { importName, importSources } from './template.utils'

type TemplateContext = {
nuxt: Nuxt;
app: NuxtApp;
Expand Down Expand Up @@ -35,9 +33,9 @@ export const clientPluginTemplate = {
getContents (ctx: TemplateContext) {
const clientPlugins = ctx.app.plugins.filter(p => !p.mode || p.mode !== 'server')
return [
importSources(clientPlugins.map(p => p.src)),
templateUtils.importSources(clientPlugins.map(p => p.src)),
'export default [',
clientPlugins.map(p => importName(p.src)).join(',\n '),
clientPlugins.map(p => templateUtils.importName(p.src)).join(',\n '),
']'
].join('\n')
}
Expand All @@ -49,10 +47,10 @@ export const serverPluginTemplate = {
const serverPlugins = ctx.app.plugins.filter(p => !p.mode || p.mode !== 'client')
return [
"import preload from '#app/plugins/preload.server'",
importSources(serverPlugins.map(p => p.src)),
templateUtils.importSources(serverPlugins.map(p => p.src)),
'export default [',
' preload,',
serverPlugins.map(p => importName(p.src)).join(',\n '),
serverPlugins.map(p => templateUtils.importName(p.src)).join(',\n '),
']'
].join('\n')
}
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt3/src/pages/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { existsSync } from 'fs'
import { defineNuxtModule, addTemplate, addPlugin } from '@nuxt/kit'
import { defineNuxtModule, addTemplate, addPlugin, templateUtils } from '@nuxt/kit'
import { resolve } from 'pathe'
import { distDir } from '../dirs'
import { resolveLayouts, resolvePagesRoutes, addComponentToRoutes } from './utils'
Expand Down Expand Up @@ -45,7 +45,7 @@ export default defineNuxtModule({
const pages = await resolvePagesRoutes(nuxt)
await nuxt.callHook('pages:extend', pages)
const serializedRoutes = addComponentToRoutes(pages)
return `export default ${JSON.stringify(serializedRoutes, null, 2).replace(/"{(.+)}"/g, '$1')}`
return `export default ${templateUtils.serialize(serializedRoutes)}`
}
})

Expand All @@ -59,7 +59,7 @@ export default defineNuxtModule({
}))
return [
'import { defineAsyncComponent } from \'vue\'',
`export default ${JSON.stringify(layoutsObject, null, 2).replace(/"{(.+)}"/g, '$1')}`
`export default ${templateUtils.serialize(layoutsObject)}`
].join('\n')
}
})
Expand Down

0 comments on commit c53b6a5

Please sign in to comment.