mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
integrate template with server renderer
This commit is contained in:
parent
750276b3f6
commit
d9ed6ecea9
@ -43,8 +43,7 @@ class Nuxt {
|
|||||||
performance: {
|
performance: {
|
||||||
gzip: {
|
gzip: {
|
||||||
threshold: 0
|
threshold: 0
|
||||||
},
|
}
|
||||||
prefetch: true
|
|
||||||
},
|
},
|
||||||
watchers: {
|
watchers: {
|
||||||
webpack: {},
|
webpack: {},
|
||||||
|
@ -93,7 +93,7 @@ export function renderRoute (url, context = {}) {
|
|||||||
// Add url and isSever to the context
|
// Add url and isSever to the context
|
||||||
context.url = url
|
context.url = url
|
||||||
context.isServer = true
|
context.isServer = true
|
||||||
// Call rendertoSting from the bundleRenderer and generate the HTML (will update the context as well)
|
// Call renderToSting from the bundleRenderer and generate the HTML (will update the context as well)
|
||||||
const self = this
|
const self = this
|
||||||
return co(function * () {
|
return co(function * () {
|
||||||
let APP = yield self.renderToString(context)
|
let APP = yield self.renderToString(context)
|
||||||
@ -105,8 +105,9 @@ export function renderRoute (url, context = {}) {
|
|||||||
if (self.options.router.base !== '/') {
|
if (self.options.router.base !== '/') {
|
||||||
HEAD += `<base href="${self.options.router.base}">`
|
HEAD += `<base href="${self.options.router.base}">`
|
||||||
}
|
}
|
||||||
HEAD += context.styles
|
HEAD += context.renderResourceHints() + context.renderStyles()
|
||||||
APP += `<script type="text/javascript">window.__NUXT__=${serialize(context.nuxt, { isJSON: true })}</script>`
|
APP += `<script type="text/javascript">window.__NUXT__=${serialize(context.nuxt, { isJSON: true })}</script>`
|
||||||
|
APP += context.renderScripts()
|
||||||
const html = self.appTemplate({
|
const html = self.appTemplate({
|
||||||
HTML_ATTRS: 'data-n-head-ssr ' + m.htmlAttrs.text(),
|
HTML_ATTRS: 'data-n-head-ssr ' + m.htmlAttrs.text(),
|
||||||
BODY_ATTRS: m.bodyAttrs.text(),
|
BODY_ATTRS: m.bodyAttrs.text(),
|
||||||
|
@ -5,8 +5,6 @@ import webpack from 'webpack'
|
|||||||
import VueSSRClientPlugin from 'vue-server-renderer/client-plugin'
|
import VueSSRClientPlugin from 'vue-server-renderer/client-plugin'
|
||||||
import HTMLPlugin from 'html-webpack-plugin'
|
import HTMLPlugin from 'html-webpack-plugin'
|
||||||
import FriendlyErrorsWebpackPlugin from 'friendly-errors-webpack-plugin'
|
import FriendlyErrorsWebpackPlugin from 'friendly-errors-webpack-plugin'
|
||||||
import ScriptExtHtmlWebpackPlugin from 'script-ext-html-webpack-plugin'
|
|
||||||
import PreloadWebpackPlugin from 'preload-webpack-plugin'
|
|
||||||
import ProgressBarPlugin from 'progress-bar-webpack-plugin'
|
import ProgressBarPlugin from 'progress-bar-webpack-plugin'
|
||||||
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
||||||
import OfflinePlugin from 'offline-plugin'
|
import OfflinePlugin from 'offline-plugin'
|
||||||
@ -46,9 +44,6 @@ export default function () {
|
|||||||
})
|
})
|
||||||
// Webpack plugins
|
// Webpack plugins
|
||||||
config.plugins = (config.plugins || []).concat([
|
config.plugins = (config.plugins || []).concat([
|
||||||
new VueSSRClientPlugin({
|
|
||||||
filename: 'client-manifest.json'
|
|
||||||
}),
|
|
||||||
// Strip comments in Vue code
|
// Strip comments in Vue code
|
||||||
new webpack.DefinePlugin(Object.assign(env, {
|
new webpack.DefinePlugin(Object.assign(env, {
|
||||||
'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'),
|
'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'),
|
||||||
@ -70,22 +65,13 @@ export default function () {
|
|||||||
}),
|
}),
|
||||||
// Generate output HTML
|
// Generate output HTML
|
||||||
new HTMLPlugin({
|
new HTMLPlugin({
|
||||||
template: this.options.appTemplatePath
|
template: this.options.appTemplatePath,
|
||||||
|
inject: false // <- Resources will be injected using vue server renderer
|
||||||
}),
|
}),
|
||||||
// Add defer to scripts
|
new VueSSRClientPlugin({
|
||||||
new ScriptExtHtmlWebpackPlugin({
|
filename: 'client-manifest.json'
|
||||||
defaultAttribute: 'defer'
|
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
|
|
||||||
if (!this.dev && this.options.performance.prefetch === true) {
|
|
||||||
// Add prefetch code-splitted routes
|
|
||||||
config.plugins.push(
|
|
||||||
new PreloadWebpackPlugin({
|
|
||||||
rel: 'prefetch'
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// client bundle progress bar
|
// client bundle progress bar
|
||||||
config.plugins.push(
|
config.plugins.push(
|
||||||
new ProgressBarPlugin()
|
new ProgressBarPlugin()
|
||||||
|
Loading…
Reference in New Issue
Block a user