import type { Nuxt, NuxtApp } from '@nuxt/kit' import { importName, importSources } from '../core/template.utils' type TemplateContext = { nuxt: Nuxt; app: NuxtApp; } export const appTemplate = { filename: 'app.mjs', getContents (ctx: TemplateContext) { return `export { default } from '${ctx.app.main}'` } } export const cssTemplate = { filename: 'css.mjs', getContents (ctx: TemplateContext) { return ctx.nuxt.options.css.map(i => `import '${i.src || i}';`).join('\n') } } export const clientPluginTemplate = { filename: 'plugins/client.mjs', getContents (ctx: TemplateContext) { const { app } = ctx return [ importSources(app.plugins.filter(p => !p.mode || p.mode !== 'server').map(p => p.src)), 'export default [', app.plugins.filter(p => !p.mode || p.mode !== 'server').map(p => importName(p.src)).join(',\n '), ']' ].join('\n') } } export const serverPluginTemplate = { filename: 'plugins/server.mjs', getContents (ctx: TemplateContext) { const { app } = ctx return [ "import preload from '#app/plugins/preload.server'", importSources(app.plugins.filter(p => !p.mode || p.mode !== 'client').map(p => p.src)), 'export default [', ' preload,', app.plugins.filter(p => !p.mode || p.mode !== 'client').map(p => importName(p.src)).join(',\n '), ']' ].join('\n') } } export const appViewTemplate = { filename: 'views/app.template.html', getContents () { return ` {{ HEAD }} {{ APP }} ` } }