mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 15:22:39 +00:00
integrate template with server renderer
This commit is contained in:
parent
750276b3f6
commit
d9ed6ecea9
@ -43,8 +43,7 @@ class Nuxt {
|
||||
performance: {
|
||||
gzip: {
|
||||
threshold: 0
|
||||
},
|
||||
prefetch: true
|
||||
}
|
||||
},
|
||||
watchers: {
|
||||
webpack: {},
|
||||
|
@ -93,7 +93,7 @@ export function renderRoute (url, context = {}) {
|
||||
// Add url and isSever to the context
|
||||
context.url = url
|
||||
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
|
||||
return co(function * () {
|
||||
let APP = yield self.renderToString(context)
|
||||
@ -105,8 +105,9 @@ export function renderRoute (url, context = {}) {
|
||||
if (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 += context.renderScripts()
|
||||
const html = self.appTemplate({
|
||||
HTML_ATTRS: 'data-n-head-ssr ' + m.htmlAttrs.text(),
|
||||
BODY_ATTRS: m.bodyAttrs.text(),
|
||||
|
@ -5,8 +5,6 @@ import webpack from 'webpack'
|
||||
import VueSSRClientPlugin from 'vue-server-renderer/client-plugin'
|
||||
import HTMLPlugin from 'html-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 { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
||||
import OfflinePlugin from 'offline-plugin'
|
||||
@ -46,9 +44,6 @@ export default function () {
|
||||
})
|
||||
// Webpack plugins
|
||||
config.plugins = (config.plugins || []).concat([
|
||||
new VueSSRClientPlugin({
|
||||
filename: 'client-manifest.json'
|
||||
}),
|
||||
// Strip comments in Vue code
|
||||
new webpack.DefinePlugin(Object.assign(env, {
|
||||
'process.env.NODE_ENV': JSON.stringify(this.dev ? 'development' : 'production'),
|
||||
@ -70,22 +65,13 @@ export default function () {
|
||||
}),
|
||||
// Generate output HTML
|
||||
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 ScriptExtHtmlWebpackPlugin({
|
||||
defaultAttribute: 'defer'
|
||||
new VueSSRClientPlugin({
|
||||
filename: 'client-manifest.json'
|
||||
})
|
||||
])
|
||||
|
||||
if (!this.dev && this.options.performance.prefetch === true) {
|
||||
// Add prefetch code-splitted routes
|
||||
config.plugins.push(
|
||||
new PreloadWebpackPlugin({
|
||||
rel: 'prefetch'
|
||||
})
|
||||
)
|
||||
}
|
||||
// client bundle progress bar
|
||||
config.plugins.push(
|
||||
new ProgressBarPlugin()
|
||||
|
Loading…
Reference in New Issue
Block a user