@@ -6,12 +6,14 @@ var webpack = require('webpack')
6
6
var MemoryFS = require ( 'memory-fs' )
7
7
var expect = require ( 'chai' ) . expect
8
8
var genId = require ( '../lib/gen-id' )
9
+ var SSR = require ( 'vue-server-renderer' )
9
10
var compiler = require ( '../lib/template-compiler' )
10
11
var normalizeNewline = require ( 'normalize-newline' )
11
12
var ExtractTextPlugin = require ( "extract-text-webpack-plugin" )
12
13
var SourceMapConsumer = require ( 'source-map' ) . SourceMapConsumer
13
14
14
- var loaderPath = 'expose-loader?vueModule!' + path . resolve ( __dirname , '../index.js' )
15
+ var rawLoaderPath = path . resolve ( __dirname , '../index.js' )
16
+ var loaderPath = 'expose-loader?vueModule!' + rawLoaderPath
15
17
var mfs = new MemoryFS ( )
16
18
var globalConfig = {
17
19
output : {
@@ -49,6 +51,11 @@ function bundle (options, cb) {
49
51
console . error ( err . message )
50
52
} )
51
53
}
54
+ if ( stats . compilation . errors ) {
55
+ stats . compilation . errors . forEach ( err => {
56
+ console . error ( err . message )
57
+ } )
58
+ }
52
59
expect ( stats . compilation . errors ) . to . be . empty
53
60
cb ( mfs . readFileSync ( '/test.build.js' ) . toString ( ) )
54
61
} )
@@ -511,4 +518,36 @@ describe('vue-loader', function () {
511
518
done ( )
512
519
} )
513
520
} )
521
+
522
+ it ( 'SSR style extraction' , done => {
523
+ bundle ( {
524
+ target : 'node' ,
525
+ entry : './test/fixtures/ssr-style.js' ,
526
+ output : {
527
+ path : '/' ,
528
+ filename : 'test.build.js' ,
529
+ libraryTarget : 'commonjs2'
530
+ } ,
531
+ externals : [ 'vue' ] ,
532
+ module : {
533
+ rules : [ { test : / \. v u e $ / , loader : rawLoaderPath } ]
534
+ }
535
+ } , code => {
536
+ const renderer = SSR . createBundleRenderer ( code )
537
+ const context = { }
538
+ renderer . renderToString ( context , ( err , res ) => {
539
+ if ( err ) return done ( err )
540
+ expect ( res ) . to . contain ( 'server-rendered' )
541
+ expect ( res ) . to . contain ( '<h1>Hello</h1>' )
542
+ expect ( res ) . to . contain ( 'Hello from Component A!' )
543
+ // from main component
544
+ expect ( context . styles ) . to . contain ( 'h1 { color: green;' )
545
+ // from imported child component
546
+ expect ( context . styles ) . to . contain ( 'comp-a h2 {\n color: #f00;' )
547
+ // from imported css file
548
+ expect ( context . styles ) . to . contain ( 'h1 { color: red;' )
549
+ done ( )
550
+ } )
551
+ } )
552
+ } )
514
553
} )
0 commit comments