File tree 3 files changed +18
-9
lines changed
3 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ module.exports = function normalizeComponent (
8
8
compiledTemplate ,
9
9
injectStyles ,
10
10
scopeId ,
11
- isServer
11
+ moduleIdentifier /* server only */
12
12
) {
13
13
var esModule
14
14
var scriptExports = rawScriptExports = rawScriptExports || { }
@@ -37,16 +37,20 @@ module.exports = function normalizeComponent (
37
37
}
38
38
39
39
var hook
40
- if ( isServer ) {
40
+ if ( moduleIdentifier ) { // server build
41
41
hook = function ( context ) {
42
42
// context is injected if this is a cached call
43
43
if ( ! context && typeof __VUE_SSR_CONTEXT__ !== 'undefined' ) {
44
44
context = __VUE_SSR_CONTEXT__
45
45
}
46
+ // inject component styles
46
47
if ( injectStyles ) {
47
48
injectStyles ( this , context )
48
49
}
49
- // TODO: register module identifier for async chunk inferrence
50
+ // register component module identifier for async chunk inferrence
51
+ if ( context && context . _registeredComponents ) {
52
+ context . _registeredComponents . add ( moduleIdentifier )
53
+ }
50
54
}
51
55
// used by ssr in case component is cached and beforeCreate
52
56
// never gets called
Original file line number Diff line number Diff line change 1
1
var path = require ( 'path' )
2
+ var hash = require ( 'hash-sum' )
2
3
var parse = require ( './parser' )
3
4
var genId = require ( './utils/gen-id' )
4
5
var normalize = require ( './utils/normalize' )
@@ -338,7 +339,7 @@ module.exports = function (content) {
338
339
// compiledTemplate,
339
340
// injectStyles,
340
341
// scopeId,
341
- // isServer
342
+ // moduleIdentifier (server only)
342
343
// )
343
344
output += 'var Component = require(' +
344
345
loaderUtils . stringifyRequest ( loaderContext , '!' + componentNormalizerPath ) +
@@ -380,9 +381,9 @@ module.exports = function (content) {
380
381
output += ' /* scopeId */\n '
381
382
output += ( hasScoped ? JSON . stringify ( moduleId ) : 'null' ) + ',\n'
382
383
383
- // isServer
384
- output += ' /* isServer */\n '
385
- output += ( isServer ? 'true' : 'false ' ) + '\n'
384
+ // moduleIdentifier (server only)
385
+ output += ' /* moduleIdentifier (server only) */\n '
386
+ output += ( isServer ? JSON . stringify ( hash ( this . request ) ) : 'null ' ) + '\n'
386
387
387
388
// close normalizeComponent call
388
389
output += ')\n'
Original file line number Diff line number Diff line change @@ -561,7 +561,7 @@ describe('vue-loader', function () {
561
561
} )
562
562
} )
563
563
564
- it ( 'SSR style extraction' , done => {
564
+ it ( 'SSR style and moduleId extraction' , done => {
565
565
bundle ( {
566
566
target : 'node' ,
567
567
entry : './test/fixtures/ssr-style.js' ,
@@ -578,7 +578,9 @@ describe('vue-loader', function () {
578
578
const renderer = SSR . createBundleRenderer ( code , {
579
579
basedir : __dirname
580
580
} )
581
- const context = { }
581
+ const context = {
582
+ _registeredComponents : new Set ( )
583
+ }
582
584
renderer . renderToString ( context , ( err , res ) => {
583
585
if ( err ) return done ( err )
584
586
expect ( res ) . to . contain ( 'server-rendered' )
@@ -590,6 +592,8 @@ describe('vue-loader', function () {
590
592
expect ( context . styles ) . to . contain ( 'comp-a h2 {\n color: #f00;' )
591
593
// from imported css file
592
594
expect ( context . styles ) . to . contain ( 'h1 { color: red;' )
595
+ // collect component identifiers during render
596
+ expect ( Array . from ( context . _registeredComponents ) . length ) . to . equal ( 2 )
593
597
done ( )
594
598
} )
595
599
} )
You can’t perform that action at this time.
0 commit comments