From 09476134eeeb12c025618919ab9a795a680a9b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Thu, 1 Oct 2020 12:11:15 +0200 Subject: [PATCH] feat: support document.html --- packages/nuxt3/src/builder/builder.ts | 9 ++++++++- packages/nuxt3/src/builder/template.ts | 1 + packages/nuxt3/src/builder/watch.ts | 3 ++- packages/nuxt3/src/config/options.ts | 15 +++++++++------ packages/nuxt3/src/vue-renderer/renderers/ssr.ts | 3 +++ packages/nuxt3/src/webpack/configs/client.ts | 4 ++-- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/nuxt3/src/builder/builder.ts b/packages/nuxt3/src/builder/builder.ts index a24bd88e6c..ecc22efdbb 100644 --- a/packages/nuxt3/src/builder/builder.ts +++ b/packages/nuxt3/src/builder/builder.ts @@ -3,6 +3,7 @@ import fsExtra from 'fs-extra' import { debounce } from 'lodash' import { BundleBuilder } from 'src/webpack' import { Nuxt } from '../core' +import { DeterminedGlobals, determineGlobals } from '../utils' import { templateData, compileTemplates, @@ -15,12 +16,14 @@ import Ignore from './ignore' export class Builder { nuxt: Nuxt + globals: DeterminedGlobals ignore: Ignore - app: NuxtApp templates: NuxtTemplate[] + app: NuxtApp constructor (nuxt) { this.nuxt = nuxt + this.globals = determineGlobals(nuxt.options.globalName, nuxt.options.globals) this.ignore = new Ignore({ rootDir: nuxt.options.srcDir, ignoreArray: nuxt.options.ignore.concat( @@ -32,6 +35,10 @@ export class Builder { build () { return build(this) } + + close () { + // TODO: close watchers + } } // Extends VueRouter diff --git a/packages/nuxt3/src/builder/template.ts b/packages/nuxt3/src/builder/template.ts index 63a911589d..fe09f160cf 100644 --- a/packages/nuxt3/src/builder/template.ts +++ b/packages/nuxt3/src/builder/template.ts @@ -11,6 +11,7 @@ export interface NuxtTemplate { export function templateData (builder) { return { + globals: builder.globals, app: builder.app } } diff --git a/packages/nuxt3/src/builder/watch.ts b/packages/nuxt3/src/builder/watch.ts index b4d1415cee..d148fec01a 100644 --- a/packages/nuxt3/src/builder/watch.ts +++ b/packages/nuxt3/src/builder/watch.ts @@ -38,7 +38,8 @@ export function createWatcher ( return { watchAll, watch, - debug + debug, + close: () => watcher.close() } } diff --git a/packages/nuxt3/src/config/options.ts b/packages/nuxt3/src/config/options.ts index 5aac8ac6ae..6e7f93c0ed 100644 --- a/packages/nuxt3/src/config/options.ts +++ b/packages/nuxt3/src/config/options.ts @@ -12,7 +12,7 @@ import { DefaultConfiguration, defaultNuxtConfigFile, getDefaultNuxtConfig } fro import { deleteProp, mergeConfigs, setProp, overrideProp, Optional } from './transformers' interface InputConfiguration { - appTemplatePath?: string + documentPath?: string layoutTransition?: string | DefaultConfiguration['layoutTransition'] loading?: true | false | DefaultConfiguration['loading'] manifest?: { @@ -197,13 +197,16 @@ function normalizeConfig (_options: CliConfiguration) { .concat(options.extensions)) // If app.html is defined, set the template path to the user template - if (options.appTemplatePath === undefined) { - options.appTemplatePath = path.resolve(options.buildDir, 'views/app.template.html') - if (fs.existsSync(path.join(options.srcDir, 'app.html'))) { - options.appTemplatePath = path.join(options.srcDir, 'app.html') + if (options.documentPath === undefined) { + options.documentPath = path.resolve(options.buildDir, 'views/document.template.html') + const userDocumentPath = path.join(options.srcDir, 'document.html') + if (fs.existsSync(userDocumentPath)) { + options.documentPath = userDocumentPath + } else { + options.watch.push(userDocumentPath) } } else { - options.appTemplatePath = path.resolve(options.srcDir, options.appTemplatePath) + options.documentPath = path.resolve(options.srcDir, options.documentPath) } overrideProp(options.build, 'publicPath', options.build.publicPath.replace(/([^/])$/, '$1/')) diff --git a/packages/nuxt3/src/vue-renderer/renderers/ssr.ts b/packages/nuxt3/src/vue-renderer/renderers/ssr.ts index 3e3ce2d6b8..482bd6b3e4 100644 --- a/packages/nuxt3/src/vue-renderer/renderers/ssr.ts +++ b/packages/nuxt3/src/vue-renderer/renderers/ssr.ts @@ -96,6 +96,9 @@ export default class SSRRenderer extends BaseRenderer { // Call Vue renderer renderToString let APP = await this.vueRenderer.renderToString(renderContext) + // Wrap with Nuxt id + APP = `
${APP}
` + // Call render:done in app await renderContext.nuxt.hooks.callHook('vue-renderer:done') diff --git a/packages/nuxt3/src/webpack/configs/client.ts b/packages/nuxt3/src/webpack/configs/client.ts index a257948102..4fb35e0622 100644 --- a/packages/nuxt3/src/webpack/configs/client.ts +++ b/packages/nuxt3/src/webpack/configs/client.ts @@ -94,7 +94,7 @@ function clientHTML (ctx: WebpackConfigContext) { config.plugins.push( new HTMLPlugin({ filename: '../server/index.ssr.html', - template: options.appTemplatePath, + template: options.documentPath, minify: options.build.html.minify as any, inject: false // Resources will be injected using bundleRenderer }) @@ -104,7 +104,7 @@ function clientHTML (ctx: WebpackConfigContext) { config.plugins.push( new HTMLPlugin({ filename: '../server/index.spa.html', - template: options.appTemplatePath, + template: options.documentPath, minify: options.build.html.minify as any, inject: true })