mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
feat: support document.html
This commit is contained in:
parent
20c2375e74
commit
09476134ee
@ -3,6 +3,7 @@ import fsExtra from 'fs-extra'
|
|||||||
import { debounce } from 'lodash'
|
import { debounce } from 'lodash'
|
||||||
import { BundleBuilder } from 'src/webpack'
|
import { BundleBuilder } from 'src/webpack'
|
||||||
import { Nuxt } from '../core'
|
import { Nuxt } from '../core'
|
||||||
|
import { DeterminedGlobals, determineGlobals } from '../utils'
|
||||||
import {
|
import {
|
||||||
templateData,
|
templateData,
|
||||||
compileTemplates,
|
compileTemplates,
|
||||||
@ -15,12 +16,14 @@ import Ignore from './ignore'
|
|||||||
|
|
||||||
export class Builder {
|
export class Builder {
|
||||||
nuxt: Nuxt
|
nuxt: Nuxt
|
||||||
|
globals: DeterminedGlobals
|
||||||
ignore: Ignore
|
ignore: Ignore
|
||||||
app: NuxtApp
|
|
||||||
templates: NuxtTemplate[]
|
templates: NuxtTemplate[]
|
||||||
|
app: NuxtApp
|
||||||
|
|
||||||
constructor (nuxt) {
|
constructor (nuxt) {
|
||||||
this.nuxt = nuxt
|
this.nuxt = nuxt
|
||||||
|
this.globals = determineGlobals(nuxt.options.globalName, nuxt.options.globals)
|
||||||
this.ignore = new Ignore({
|
this.ignore = new Ignore({
|
||||||
rootDir: nuxt.options.srcDir,
|
rootDir: nuxt.options.srcDir,
|
||||||
ignoreArray: nuxt.options.ignore.concat(
|
ignoreArray: nuxt.options.ignore.concat(
|
||||||
@ -32,6 +35,10 @@ export class Builder {
|
|||||||
build () {
|
build () {
|
||||||
return build(this)
|
return build(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close () {
|
||||||
|
// TODO: close watchers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extends VueRouter
|
// Extends VueRouter
|
||||||
|
@ -11,6 +11,7 @@ export interface NuxtTemplate {
|
|||||||
|
|
||||||
export function templateData (builder) {
|
export function templateData (builder) {
|
||||||
return {
|
return {
|
||||||
|
globals: builder.globals,
|
||||||
app: builder.app
|
app: builder.app
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,8 @@ export function createWatcher (
|
|||||||
return {
|
return {
|
||||||
watchAll,
|
watchAll,
|
||||||
watch,
|
watch,
|
||||||
debug
|
debug,
|
||||||
|
close: () => watcher.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import { DefaultConfiguration, defaultNuxtConfigFile, getDefaultNuxtConfig } fro
|
|||||||
import { deleteProp, mergeConfigs, setProp, overrideProp, Optional } from './transformers'
|
import { deleteProp, mergeConfigs, setProp, overrideProp, Optional } from './transformers'
|
||||||
|
|
||||||
interface InputConfiguration {
|
interface InputConfiguration {
|
||||||
appTemplatePath?: string
|
documentPath?: string
|
||||||
layoutTransition?: string | DefaultConfiguration['layoutTransition']
|
layoutTransition?: string | DefaultConfiguration['layoutTransition']
|
||||||
loading?: true | false | DefaultConfiguration['loading']
|
loading?: true | false | DefaultConfiguration['loading']
|
||||||
manifest?: {
|
manifest?: {
|
||||||
@ -197,13 +197,16 @@ function normalizeConfig (_options: CliConfiguration) {
|
|||||||
.concat(options.extensions))
|
.concat(options.extensions))
|
||||||
|
|
||||||
// If app.html is defined, set the template path to the user template
|
// If app.html is defined, set the template path to the user template
|
||||||
if (options.appTemplatePath === undefined) {
|
if (options.documentPath === undefined) {
|
||||||
options.appTemplatePath = path.resolve(options.buildDir, 'views/app.template.html')
|
options.documentPath = path.resolve(options.buildDir, 'views/document.template.html')
|
||||||
if (fs.existsSync(path.join(options.srcDir, 'app.html'))) {
|
const userDocumentPath = path.join(options.srcDir, 'document.html')
|
||||||
options.appTemplatePath = path.join(options.srcDir, 'app.html')
|
if (fs.existsSync(userDocumentPath)) {
|
||||||
|
options.documentPath = userDocumentPath
|
||||||
|
} else {
|
||||||
|
options.watch.push(userDocumentPath)
|
||||||
}
|
}
|
||||||
} else {
|
} 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/'))
|
overrideProp(options.build, 'publicPath', options.build.publicPath.replace(/([^/])$/, '$1/'))
|
||||||
|
@ -96,6 +96,9 @@ export default class SSRRenderer extends BaseRenderer {
|
|||||||
// Call Vue renderer renderToString
|
// Call Vue renderer renderToString
|
||||||
let APP = await this.vueRenderer.renderToString(renderContext)
|
let APP = await this.vueRenderer.renderToString(renderContext)
|
||||||
|
|
||||||
|
// Wrap with Nuxt id
|
||||||
|
APP = `<div id="${this.serverContext.globals.id}">${APP}</div>`
|
||||||
|
|
||||||
// Call render:done in app
|
// Call render:done in app
|
||||||
await renderContext.nuxt.hooks.callHook('vue-renderer:done')
|
await renderContext.nuxt.hooks.callHook('vue-renderer:done')
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ function clientHTML (ctx: WebpackConfigContext) {
|
|||||||
config.plugins.push(
|
config.plugins.push(
|
||||||
new HTMLPlugin({
|
new HTMLPlugin({
|
||||||
filename: '../server/index.ssr.html',
|
filename: '../server/index.ssr.html',
|
||||||
template: options.appTemplatePath,
|
template: options.documentPath,
|
||||||
minify: options.build.html.minify as any,
|
minify: options.build.html.minify as any,
|
||||||
inject: false // Resources will be injected using bundleRenderer
|
inject: false // Resources will be injected using bundleRenderer
|
||||||
})
|
})
|
||||||
@ -104,7 +104,7 @@ function clientHTML (ctx: WebpackConfigContext) {
|
|||||||
config.plugins.push(
|
config.plugins.push(
|
||||||
new HTMLPlugin({
|
new HTMLPlugin({
|
||||||
filename: '../server/index.spa.html',
|
filename: '../server/index.spa.html',
|
||||||
template: options.appTemplatePath,
|
template: options.documentPath,
|
||||||
minify: options.build.html.minify as any,
|
minify: options.build.html.minify as any,
|
||||||
inject: true
|
inject: true
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user