Skip to content

Commit

Permalink
fix(ssr): render initial and used async css chunks (#7902)
Browse files Browse the repository at this point in the history
compatibility with webpack 4 + mini CSS extraction

close #7897
  • Loading branch information
clarkdo authored and yyx990803 committed Apr 7, 2018
1 parent ae6dcd6 commit 575b6e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/server/template-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ export default class TemplateRenderer {
}

renderStyles (context: Object): string {
const cssFiles = this.clientManifest
? this.clientManifest.all.filter(isCSS)
: []
const initial = this.preloadFiles || []
const async = this.getUsedAsyncFiles(context) || []
const cssFiles = initial.concat(async).filter(({ file }) => isCSS(file))
return (
// render links for css files
(cssFiles.length
? cssFiles.map(file => `<link rel="stylesheet" href="${this.publicPath}/${file}">`).join('')
? cssFiles.map(({ file }) => `<link rel="stylesheet" href="${this.publicPath}/${file}">`).join('')
: '') +
// context.styles is a getter exposed by vue-style-loader which contains
// the inline component styles collected during SSR
Expand Down Expand Up @@ -202,10 +202,10 @@ export default class TemplateRenderer {

renderScripts (context: Object): string {
if (this.clientManifest) {
const initial = this.preloadFiles
const async = this.getUsedAsyncFiles(context)
const initial = this.preloadFiles.filter(({ file }) => isJS(file))
const async = (this.getUsedAsyncFiles(context) || []).filter(({ file }) => isJS(file))
const needed = [initial[0]].concat(async || [], initial.slice(1))
return needed.filter(({ file }) => isJS(file)).map(({ file }) => {
return needed.map(({ file }) => {
return `<script src="${this.publicPath}/${file}" defer></script>`
}).join('')
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/server/webpack-plugin/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const hash = require('hash-sum')
const uniq = require('lodash.uniq')
import { isJS } from './util'
import { isJS, isCSS } from './util'

export default class VueSSRClientPlugin {
constructor (options = {}) {
Expand All @@ -19,10 +19,10 @@ export default class VueSSRClientPlugin {
const initialFiles = uniq(Object.keys(stats.entrypoints)
.map(name => stats.entrypoints[name].assets)
.reduce((assets, all) => all.concat(assets), [])
.filter(isJS))
.filter((file) => isJS(file) || isCSS(file)))

const asyncFiles = allFiles
.filter(isJS)
.filter((file) => isJS(file) || isCSS(file))
.filter(file => initialFiles.indexOf(file) < 0)

const manifest = {
Expand Down

0 comments on commit 575b6e7

Please sign in to comment.