@@ -13,8 +13,13 @@ const EXPORT_REGEX = /(export[\s\r\n]+default|module[\s\r\n]*\.exports[^=]*=)[\s
13
13
function inlineStyle ( name , style , config ) {
14
14
let output = `var ${ name } = ${ style . modules ? _s ( style . modules ) : '{}' } \n`
15
15
16
- output += `${ name } .__inject__ = function (context) {\n` +
17
- ` ${ STYLE_INJECTOR_IDENTIFIER } (${ _s ( config . shortFilePath ) } , [[${ _s ( config . shortFilePath ) } , ${ _s ( style . code ) } , ${ _s ( style . descriptor . attrs . media ) } , ${ _s ( style . map ) } ]], ${ config . isProduction } , context)\n` +
16
+ output +=
17
+ `${ name } .__inject__ = function (context) {\n` +
18
+ ` ${ STYLE_INJECTOR_IDENTIFIER } (${ _s ( config . shortFilePath ) } , [[${ _s (
19
+ config . shortFilePath
20
+ ) } , ${ _s ( style . code ) } , ${ _s ( style . descriptor . attrs . media ) } , ${ _s (
21
+ style . map
22
+ ) } ]], ${ config . isProduction } , context)\n` +
18
23
`}\n`
19
24
20
25
return output
@@ -33,41 +38,52 @@ const Source = struct({
33
38
map : 'object?' ,
34
39
descriptor : struct . union ( [ 'object' , 'null' ] )
35
40
} ,
36
- styles : struct . list ( [ {
37
- id : struct . union ( [ 'string?' , 'null' ] ) ,
38
- code : struct . union ( [ 'string?' , 'null' ] ) ,
39
- map : 'object?' ,
40
- modules : 'object?' ,
41
- descriptor : struct . union ( [ 'object' , 'null' ] )
42
- } ] ) ,
43
- customBlocks : struct . list ( [ {
44
- id : 'string?' ,
45
- code : 'string?' ,
46
- map : 'object?' ,
47
- descriptor : struct . union ( [ 'object' , 'null' ] )
48
- } ] )
49
- } )
50
- const Config = any => defaultsdeep ( struct ( {
51
- esModule : 'boolean?' ,
52
- require : 'object?' ,
53
- scopeId : 'string?' ,
54
- moduleIdentifier : 'string?' ,
55
- isServer : 'boolean?' ,
56
- isProduction : 'boolean?' ,
57
- hasStyleInjectFn : 'boolean?' ,
58
- onWarn : 'function?'
59
- } ) ( any ) , {
60
- esModule : true ,
61
- require : {
62
- normalizeComponent : 'vue-component-compiler/src/runtime/normalize-component' ,
63
- injectStyleClient : 'vue-component-compiler/src/runtime/inject-style-client' ,
64
- injectStyleServer : 'vue-component-compiler/src/runtime/inject-style-server'
65
- } ,
66
- isServer : false ,
67
- isProduction : true ,
68
- hasStyleInjectFn : false ,
69
- onWarn : ( ) => message => console . warn ( message )
41
+ styles : struct . list ( [
42
+ {
43
+ id : struct . union ( [ 'string?' , 'null' ] ) ,
44
+ code : struct . union ( [ 'string?' , 'null' ] ) ,
45
+ map : 'object?' ,
46
+ modules : 'object?' ,
47
+ descriptor : struct . union ( [ 'object' , 'null' ] )
48
+ }
49
+ ] ) ,
50
+ customBlocks : struct . list ( [
51
+ {
52
+ id : 'string?' ,
53
+ code : 'string?' ,
54
+ map : 'object?' ,
55
+ descriptor : struct . union ( [ 'object' , 'null' ] )
56
+ }
57
+ ] )
70
58
} )
59
+ const Config = any =>
60
+ defaultsdeep (
61
+ struct ( {
62
+ esModule : 'boolean?' ,
63
+ require : 'object?' ,
64
+ scopeId : 'string?' ,
65
+ moduleIdentifier : 'string?' ,
66
+ isServer : 'boolean?' ,
67
+ isProduction : 'boolean?' ,
68
+ hasStyleInjectFn : 'boolean?' ,
69
+ onWarn : 'function?'
70
+ } ) ( any ) ,
71
+ {
72
+ esModule : true ,
73
+ require : {
74
+ normalizeComponent :
75
+ 'vue-component-compiler/src/runtime/normalize-component' ,
76
+ injectStyleClient :
77
+ 'vue-component-compiler/src/runtime/inject-style-client' ,
78
+ injectStyleServer :
79
+ 'vue-component-compiler/src/runtime/inject-style-server'
80
+ } ,
81
+ isServer : false ,
82
+ isProduction : true ,
83
+ hasStyleInjectFn : false ,
84
+ onWarn : ( ) => message => console . warn ( message )
85
+ }
86
+ )
71
87
72
88
module . exports = function assemble ( source , filename , config ) {
73
89
assertType ( { filename } , 'string' )
@@ -86,13 +102,17 @@ module.exports = function assemble (source, filename, config) {
86
102
87
103
// Import style injector.
88
104
output += importStatement (
89
- config . isServer ? config . require . injectStyleServer : config . require . injectStyleClient ,
105
+ config . isServer
106
+ ? config . require . injectStyleServer
107
+ : config . require . injectStyleClient ,
90
108
{ name : STYLE_INJECTOR_IDENTIFIER , esModule : config . esModule }
91
109
)
92
110
styles . forEach ( ( style , i ) => {
93
111
const IMPORT_NAME = `__vue_style_${ i } __`
94
- const moduleName = ( style . descriptor . module === true ) ? '$style' : style . descriptor . module
95
- const needsNamedImport = config . hasStyleInjectFn || typeof moduleName === 'string'
112
+ const moduleName =
113
+ style . descriptor . module === true ? '$style' : style . descriptor . module
114
+ const needsNamedImport =
115
+ config . hasStyleInjectFn || typeof moduleName === 'string'
96
116
const runInjection = `${ IMPORT_NAME } && ${ IMPORT_NAME } .__inject__ && ${ IMPORT_NAME } .__inject__(context)\n`
97
117
98
118
if ( typeof style . code === 'string' ) {
@@ -116,12 +136,20 @@ module.exports = function assemble (source, filename, config) {
116
136
} )
117
137
} else {
118
138
cssModules [ moduleName ] = true
119
- styleInjectionCode += `__vue_css_modules__[${ _s ( moduleName ) } ] = ${ IMPORT_NAME } \n` +
120
- `Object.defineProperty(this, ${ _s ( moduleName ) } , { get: function () { return __vue_css_modules__[${ _s ( moduleName ) } ] }})\n`
139
+ styleInjectionCode +=
140
+ `__vue_css_modules__[${ _s ( moduleName ) } ] = ${ IMPORT_NAME } \n` +
141
+ `Object.defineProperty(this, ${ _s (
142
+ moduleName
143
+ ) } , { get: function () { return __vue_css_modules__[${ _s (
144
+ moduleName
145
+ ) } ] }})\n`
121
146
}
122
147
}
123
148
} )
124
- output += `function ${ STYLE_IDENTIFIER } (context) {\n` + pad ( styleInjectionCode ) + `}\n`
149
+ output +=
150
+ `function ${ STYLE_IDENTIFIER } (context) {\n` +
151
+ pad ( styleInjectionCode ) +
152
+ `}\n`
125
153
}
126
154
127
155
// we require the component normalizer function, and call it like so:
@@ -138,7 +166,10 @@ module.exports = function assemble (source, filename, config) {
138
166
} )
139
167
// <script>
140
168
if ( typeof script . code === 'string' ) {
141
- output += '\n/* script */\n' + script . code . replace ( EXPORT_REGEX , '\nvar __vue_script__ = ' ) + '\n'
169
+ output +=
170
+ '\n/* script */\n' +
171
+ script . code . replace ( EXPORT_REGEX , '\nvar __vue_script__ = ' ) +
172
+ '\n'
142
173
} else {
143
174
output += importStatement ( script . id , {
144
175
esModule : config . esModule ,
@@ -151,10 +182,11 @@ module.exports = function assemble (source, filename, config) {
151
182
152
183
// <template>
153
184
if ( typeof render . code === 'string' ) {
154
- output += `\n/* template */\n` +
155
- `var __vue_template__ = (function () {\n${
156
- pad ( render . code . replace ( EXPORT_REGEX , 'return ' ) . trim ( ) )
157
- } })()\n`
185
+ output +=
186
+ `\n/* template */\n` +
187
+ `var __vue_template__ = (function () {\n${ pad (
188
+ render . code . replace ( EXPORT_REGEX , 'return ' ) . trim ( )
189
+ ) } })()\n`
158
190
} else {
159
191
output += importStatement ( render . id , {
160
192
esModule : config . esModule ,
@@ -164,34 +196,49 @@ module.exports = function assemble (source, filename, config) {
164
196
165
197
// template functional
166
198
output += '\n/* template functional */\n'
167
- output += 'var __vue_template_functional__ = ' + ( render . descriptor && render . descriptor . attrs && render . descriptor . attrs . functional ? 'true' : 'false' ) + '\n'
199
+ output +=
200
+ 'var __vue_template_functional__ = ' +
201
+ ( render . descriptor &&
202
+ render . descriptor . attrs &&
203
+ render . descriptor . attrs . functional
204
+ ? 'true'
205
+ : 'false' ) +
206
+ '\n'
168
207
169
208
// style
170
209
output += '\n/* styles */\n'
171
- output += 'var __vue_styles__ = ' + ( styles . length ? STYLE_IDENTIFIER : 'null' ) + '\n'
210
+ output +=
211
+ 'var __vue_styles__ = ' + ( styles . length ? STYLE_IDENTIFIER : 'null' ) + '\n'
172
212
173
213
// scopeId
174
214
output += '\n/* scopeId */\n'
175
- output += 'var __vue_scopeId__ = ' + ( hasScoped ? _s ( config . scopeId ) : 'null' ) + '\n'
215
+ output +=
216
+ 'var __vue_scopeId__ = ' + ( hasScoped ? _s ( config . scopeId ) : 'null' ) + '\n'
176
217
177
218
// moduleIdentifier (server only)
178
219
output += '\n/* moduleIdentifier (server only) */\n'
179
- output += 'var __vue_module_identifier__ = ' + ( config . isServer ? _s ( config . moduleIdentifier ) : 'null' ) + '\n'
220
+ output +=
221
+ 'var __vue_module_identifier__ = ' +
222
+ ( config . isServer ? _s ( config . moduleIdentifier ) : 'null' ) +
223
+ '\n'
180
224
181
225
// close normalizeComponent call
182
- output += `\nvar ${ COMPONENT_IDENTIFIER } = ${ NORMALIZE_COMPONENT_IDENTIFIER } (\n` +
183
- ' __vue_script__,\n' +
184
- ' __vue_template__,\n' +
185
- ' __vue_template_functional__,\n' +
186
- ' __vue_styles__,\n' +
187
- ' __vue_scopeId__,\n' +
188
- ' __vue_module_identifier__\n' +
189
- ')\n'
226
+ output +=
227
+ `\nvar ${ COMPONENT_IDENTIFIER } = ${ NORMALIZE_COMPONENT_IDENTIFIER } (\n` +
228
+ ' __vue_script__,\n' +
229
+ ' __vue_template__,\n' +
230
+ ' __vue_template_functional__,\n' +
231
+ ' __vue_styles__,\n' +
232
+ ' __vue_scopeId__,\n' +
233
+ ' __vue_module_identifier__\n' +
234
+ ')\n'
190
235
191
236
// development-only code
192
237
if ( ! config . isProduction ) {
193
238
// add filename in dev
194
- output += `${ COMPONENT_IDENTIFIER } .options.__file = ${ _s ( config . shortFilePath ) } \n`
239
+ output += `${ COMPONENT_IDENTIFIER } .options.__file = ${ _s (
240
+ config . shortFilePath
241
+ ) } \n`
195
242
}
196
243
197
244
if ( customBlocks . length ) {
@@ -218,5 +265,11 @@ module.exports = function assemble (source, filename, config) {
218
265
}
219
266
220
267
function pad ( content ) {
221
- return content . trim ( ) . split ( '\n' ) . map ( line => ' ' + line ) . join ( '\n' ) + '\n'
268
+ return (
269
+ content
270
+ . trim ( )
271
+ . split ( '\n' )
272
+ . map ( line => ' ' + line )
273
+ . join ( '\n' ) + '\n'
274
+ )
222
275
}
0 commit comments