@@ -155,12 +155,12 @@ module.exports = function (content) {
155
155
// add requires for styles
156
156
let cssModules
157
157
if ( parts . styles . length ) {
158
- const needsLazyInjection = isServer || isShadowMode
158
+ const needsExplicitInjection = isServer || isShadowMode
159
159
let styleInjectionCode = 'function injectStyle (context) {\n'
160
160
if ( needsHotReload ) {
161
161
styleInjectionCode += ` if (disposed) return\n`
162
162
}
163
- if ( needsLazyInjection ) {
163
+ if ( needsExplicitInjection ) {
164
164
styleInjectionCode += `var i\n`
165
165
}
166
166
parts . styles . forEach ( ( style , i ) => {
@@ -174,7 +174,7 @@ module.exports = function (content) {
174
174
// vue-style-loader exposes inject functions in SSR or shadow mode so they
175
175
// are always called
176
176
const invokeStyle =
177
- needsLazyInjection && hasVueStyleLoader
177
+ needsExplicitInjection && hasVueStyleLoader
178
178
? code => `;(i=${ code } ,i.__inject__&&i.__inject__(context),i)\n`
179
179
: code => ` ${ code } \n`
180
180
@@ -241,27 +241,6 @@ module.exports = function (content) {
241
241
output += styleInjectionCode
242
242
}
243
243
244
- // we require the component normalizer function, and call it like so:
245
- // normalizeComponent(
246
- // scriptExports,
247
- // compiledTemplate,
248
- // functionalTemplate,
249
- // injectStyles,
250
- // scopeId,
251
- // moduleIdentifier (server only)
252
- // )
253
- const componentNormalizerRequest = loaderUtils . stringifyRequest (
254
- loaderContext ,
255
- '!' + componentNormalizerPath
256
- )
257
- if ( ! options . esModule ) {
258
- output +=
259
- `var normalizeComponent = require(${ componentNormalizerRequest } ).default\n`
260
- } else {
261
- output +=
262
- `import normalizeComponent from ${ componentNormalizerRequest } \n`
263
- }
264
-
265
244
// <script>
266
245
output += '/* script */\n'
267
246
const script = parts . script
@@ -322,12 +301,11 @@ module.exports = function (content) {
322
301
323
302
// style
324
303
// the injection function is passed to the normalizer and injected into
325
- // component lifecycle hooks. In shadow mode, we expose the inject function
326
- // directly on the component's options so we don't pass it here.
304
+ // component lifecycle hooks.
327
305
output += '/* styles */\n'
328
306
output +=
329
307
'var __vue_styles__ = ' +
330
- ( parts . styles . length && ! isShadowMode ? 'injectStyle' : 'null' ) +
308
+ ( parts . styles . length ? 'injectStyle' : 'null' ) +
331
309
'\n'
332
310
333
311
// scopeId
@@ -344,7 +322,27 @@ module.exports = function (content) {
344
322
( isServer ? JSON . stringify ( hash ( this . request ) ) : 'null' ) +
345
323
'\n'
346
324
347
- // close normalizeComponent call
325
+ // we require the component normalizer function, and call it like so:
326
+ // normalizeComponent(
327
+ // scriptExports,
328
+ // compiledTemplate,
329
+ // functionalTemplate,
330
+ // injectStyles,
331
+ // scopeId,
332
+ // moduleIdentifier, (server only)
333
+ // isShadowMode (vue-cli only)
334
+ // )
335
+ const componentNormalizerRequest = loaderUtils . stringifyRequest (
336
+ loaderContext ,
337
+ '!' + componentNormalizerPath
338
+ )
339
+ if ( ! options . esModule ) {
340
+ output +=
341
+ `var normalizeComponent = require(${ componentNormalizerRequest } ).default\n`
342
+ } else {
343
+ output +=
344
+ `import normalizeComponent from ${ componentNormalizerRequest } \n`
345
+ }
348
346
output +=
349
347
'var Component = normalizeComponent(\n' +
350
348
' __vue_script__,\n' +
@@ -353,26 +351,9 @@ module.exports = function (content) {
353
351
' __vue_styles__,\n' +
354
352
' __vue_scopeId__,\n' +
355
353
' __vue_module_identifier__\n' +
354
+ ( isShadowMode ? `,true` : `` ) +
356
355
')\n'
357
356
358
- // expose style injection on options
359
- // this will be used by vue-cli's web component entry
360
- if ( isShadowMode ) {
361
- // the shadow inject id will be the module id of the entry Vue component,
362
- // which is the frist Vue component encountered in this compilation
363
- let shadowInjectId = process . env . VUE_SHADOW_INJECT_ID
364
- if ( ! shadowInjectId ) {
365
- shadowInjectId = process . env . VUE_SHADOW_INJECT_ID =
366
- `__vue_shadow_injector__${ moduleId . replace ( `data-v-` , '' ) } `
367
- }
368
- output +=
369
- `var shadowInjectId = Component.options.__shadowInjectId = '${ shadowInjectId } '\n` +
370
- `var injectors = window[shadowInjectId] || (window[shadowInjectId] = [])\n`
371
- if ( parts . styles . length ) {
372
- output += `injectors.push(injectStyle)`
373
- }
374
- }
375
-
376
357
// development-only code
377
358
if ( ! isProduction ) {
378
359
// add filename in dev
0 commit comments