mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 17:07:22 +00:00
refactor(app): remove lodash template files (#543)
This commit is contained in:
parent
3671cfc772
commit
f4cf2199a5
@ -1,6 +1,5 @@
|
|||||||
dist
|
dist
|
||||||
node_modules
|
node_modules
|
||||||
_templates
|
|
||||||
schema
|
schema
|
||||||
**/*.tmpl.*
|
**/*.tmpl.*
|
||||||
sw.js
|
sw.js
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export { default } from '<%= app.main %>'
|
|
@ -1 +0,0 @@
|
|||||||
<%= nuxt.options.css.map(i => `import '${i.src || i}';`).join('') %>
|
|
@ -1,5 +0,0 @@
|
|||||||
<%= utils.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 => utils.importName(p.src)).join(',\n ') %>
|
|
||||||
]
|
|
@ -1,8 +0,0 @@
|
|||||||
import preload from '#app/plugins/preload.server'
|
|
||||||
|
|
||||||
<%= utils.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 => utils.importName(p.src)).join(',\n ') %>
|
|
||||||
]
|
|
@ -1,12 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html {{ HTML_ATTRS }}>
|
|
||||||
|
|
||||||
<head {{ HEAD_ATTRS }}>
|
|
||||||
{{ HEAD }}
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body {{ BODY_ATTRS }}>
|
|
||||||
{{ APP }}
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
71
packages/nuxt3/src/app/templates.ts
Normal file
71
packages/nuxt3/src/app/templates.ts
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
import type { Nuxt, NuxtApp } from '@nuxt/kit'
|
||||||
|
|
||||||
|
import * as templateUtils from '../core/template.utils'
|
||||||
|
|
||||||
|
type TemplateContext = {
|
||||||
|
nuxt: Nuxt;
|
||||||
|
app: NuxtApp;
|
||||||
|
utils: typeof templateUtils
|
||||||
|
}
|
||||||
|
|
||||||
|
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, utils } = ctx
|
||||||
|
return [
|
||||||
|
utils.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 => utils.importName(p.src)).join(',\n '),
|
||||||
|
']'
|
||||||
|
].join('\n')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const serverPluginTemplate = {
|
||||||
|
filename: 'plugins/server.mjs',
|
||||||
|
getContents (ctx: TemplateContext) {
|
||||||
|
const { app, utils } = ctx
|
||||||
|
return [
|
||||||
|
"import preload from '#app/plugins/preload.server'",
|
||||||
|
utils.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 => utils.importName(p.src)).join(',\n '),
|
||||||
|
']'
|
||||||
|
].join('\n')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const appViewTemplate = {
|
||||||
|
filename: 'views/app.template.html',
|
||||||
|
getContents () {
|
||||||
|
return `<!DOCTYPE html>
|
||||||
|
<html {{ HTML_ATTRS }}>
|
||||||
|
|
||||||
|
<head {{ HEAD_ATTRS }}>
|
||||||
|
{{ HEAD }}
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body {{ BODY_ATTRS }}>
|
||||||
|
{{ APP }}
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,10 @@
|
|||||||
import { resolve, join, relative } from 'upath'
|
import { resolve } from 'upath'
|
||||||
import globby from 'globby'
|
|
||||||
import lodashTemplate from 'lodash/template'
|
import lodashTemplate from 'lodash/template'
|
||||||
import defu from 'defu'
|
import defu from 'defu'
|
||||||
import { tryResolvePath, resolveFiles, Nuxt, NuxtApp, NuxtTemplate, normalizePlugin, normalizeTemplate } from '@nuxt/kit'
|
import { tryResolvePath, resolveFiles, Nuxt, NuxtApp, NuxtTemplate, normalizePlugin, normalizeTemplate } from '@nuxt/kit'
|
||||||
import { readFile, writeFile } from 'fs-extra'
|
import { readFile, writeFile } from 'fs-extra'
|
||||||
|
|
||||||
|
import * as defaultTemplates from '../app/templates'
|
||||||
import * as templateUtils from './template.utils'
|
import * as templateUtils from './template.utils'
|
||||||
|
|
||||||
export function createApp (nuxt: Nuxt, options: Partial<NuxtApp> = {}): NuxtApp {
|
export function createApp (nuxt: Nuxt, options: Partial<NuxtApp> = {}): NuxtApp {
|
||||||
@ -19,15 +20,8 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp) {
|
|||||||
// Resolve app
|
// Resolve app
|
||||||
await resolveApp(nuxt, app)
|
await resolveApp(nuxt, app)
|
||||||
|
|
||||||
// Scan app templates
|
|
||||||
const templatesDir = join(nuxt.options.appDir, '_templates')
|
|
||||||
const templateFiles = await globby(join(templatesDir, '/**'))
|
|
||||||
app.templates = templateFiles
|
|
||||||
.filter(src => !src.endsWith('.d.ts'))
|
|
||||||
.map(src => ({ src, filename: relative(templatesDir, src) } as NuxtTemplate))
|
|
||||||
|
|
||||||
// User templates from options.build.templates
|
// User templates from options.build.templates
|
||||||
app.templates = app.templates.concat(nuxt.options.build.templates)
|
app.templates = Object.values(defaultTemplates).concat(nuxt.options.build.templates)
|
||||||
|
|
||||||
// Extend templates with hook
|
// Extend templates with hook
|
||||||
await nuxt.callHook('app:templates', app)
|
await nuxt.callHook('app:templates', app)
|
||||||
|
Loading…
Reference in New Issue
Block a user