@@ -17,6 +17,7 @@ module.exports.pitch = function (remainingRequest) {
17
17
var addStylesClientPath = loaderUtils . stringifyRequest ( this , '!' + path . join ( __dirname , 'lib/addStylesClient.js' ) )
18
18
var addStylesServerPath = loaderUtils . stringifyRequest ( this , '!' + path . join ( __dirname , 'lib/addStylesServer.js' ) )
19
19
20
+ var isVue = / \. v u e $ / . test ( remainingRequest )
20
21
var request = loaderUtils . stringifyRequest ( this , '!!' + remainingRequest )
21
22
var id = JSON . stringify ( hash ( request ) )
22
23
@@ -56,12 +57,21 @@ module.exports.pitch = function (remainingRequest) {
56
57
return shared . concat ( code ) . join ( '\n' )
57
58
} else {
58
59
// on the server: attach to Vue SSR context
59
- return shared . concat ( [
60
- '// add CSS to SSR context' ,
61
- 'var add = require(' + addStylesServerPath + ')' ,
62
- 'module.exports.__inject__ = function (context) {' ,
63
- ' add(' + id + ', content, ' + isProduction + ', context)' ,
64
- '};'
65
- ] ) . join ( '\n' )
60
+ if ( isVue ) {
61
+ // inside *.vue file: expose a function so it can be called in
62
+ // component's lifecycle hooks
63
+ return shared . concat ( [
64
+ '// add CSS to SSR context' ,
65
+ 'var add = require(' + addStylesServerPath + ')' ,
66
+ 'module.exports.__inject__ = function (context) {' ,
67
+ ' add(' + id + ', content, ' + isProduction + ', context)' ,
68
+ '};'
69
+ ] ) . join ( '\n' )
70
+ } else {
71
+ // normal import
72
+ return shared . concat ( [
73
+ 'require(' + addStylesServerPath + ')(' + id + ', content, ' + isProduction + ')'
74
+ ] ) . join ( '\n' )
75
+ }
66
76
}
67
77
}
0 commit comments