@@ -17,6 +17,7 @@ module.exports.pitch = function (remainingRequest) {
1717 var addStylesClientPath = loaderUtils . stringifyRequest ( this , '!' + path . join ( __dirname , 'lib/addStylesClient.js' ) )
1818 var addStylesServerPath = loaderUtils . stringifyRequest ( this , '!' + path . join ( __dirname , 'lib/addStylesServer.js' ) )
1919
20+ var isVue = / \. v u e $ / . test ( remainingRequest )
2021 var request = loaderUtils . stringifyRequest ( this , '!!' + remainingRequest )
2122 var id = JSON . stringify ( hash ( request ) )
2223
@@ -56,12 +57,21 @@ module.exports.pitch = function (remainingRequest) {
5657 return shared . concat ( code ) . join ( '\n' )
5758 } else {
5859 // 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+ }
6676 }
6777}
0 commit comments