44 parseVuePartRequest ,
55 resolveVuePart ,
66 isVuePartRequest ,
7- transformRequireToImport
7+ transformRequireToImport ,
88} from './utils'
99import {
1010 createDefaultCompiler ,
@@ -13,17 +13,14 @@ import {
1313 StyleOptions ,
1414 TemplateOptions ,
1515 StyleCompileResult ,
16- DescriptorCompileResult
16+ DescriptorCompileResult ,
1717} from '@vue/component-compiler'
1818import MagicString from 'magic-string'
1919import { Plugin , RawSourceMap } from 'rollup'
2020import * as path from 'path'
2121import { parse , SFCDescriptor , SFCBlock } from '@vue/component-compiler-utils'
2222import debug from 'debug'
23- import {
24- VueTemplateCompiler ,
25- VueTemplateCompilerParseOptions
26- } from '@vue/component-compiler-utils/dist/types'
23+ import { VueTemplateCompiler , VueTemplateCompilerParseOptions } from '@vue/component-compiler-utils/dist/types'
2724
2825const templateCompiler = require ( 'vue-template-compiler' )
2926const hash = require ( 'hash-sum' )
@@ -153,6 +150,10 @@ export interface VuePluginOptions {
153150 */
154151 styleInjectorSSR ?: string
155152
153+ styleInjectorShadow ?: string
154+
155+ isWebComponent ?: boolean
156+
156157 beforeAssemble ?( descriptor : DescriptorCompileResult ) : DescriptorCompileResult
157158}
158159/**
@@ -163,25 +164,20 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin {
163164 const isProduction =
164165 opts . template && typeof opts . template . isProduction === 'boolean'
165166 ? opts . template . isProduction
166- : process . env . NODE_ENV === 'production' ||
167- process . env . BUILD === 'production'
167+ : process . env . NODE_ENV === 'production' || process . env . BUILD === 'production'
168168
169169 d ( 'Version ' + version )
170170 d ( `Build environment: ${ isProduction ? 'production' : 'development' } ` )
171171 d ( `Build target: ${ process . env . VUE_ENV || 'browser' } ` )
172172
173- if ( ! opts . normalizer )
174- opts . normalizer = '~' + 'vue-runtime-helpers/dist/normalize-component.js'
175- if ( ! opts . styleInjector )
176- opts . styleInjector =
177- '~' + 'vue-runtime-helpers/dist/inject-style/browser.js'
178- if ( ! opts . styleInjectorSSR )
179- opts . styleInjectorSSR =
180- '~' + 'vue-runtime-helpers/dist/inject-style/server.js'
173+ if ( ! opts . normalizer ) opts . normalizer = '~' + 'vue-runtime-helpers/dist/normalize-component.mjs'
174+ if ( ! opts . styleInjector ) opts . styleInjector = '~' + 'vue-runtime-helpers/dist/inject-style/browser.mjs'
175+ if ( ! opts . styleInjectorSSR ) opts . styleInjectorSSR = '~' + 'vue-runtime-helpers/dist/inject-style/server.mjs'
176+ if ( ! opts . styleInjectorSSR ) opts . styleInjectorShadow = '~' + 'vue-runtime-helpers/dist/inject-style/shadow.mjs'
181177
182178 createVuePartRequest . defaultLang = {
183179 ...createVuePartRequest . defaultLang ,
184- ...opts . defaultLang
180+ ...opts . defaultLang ,
185181 }
186182
187183 const shouldExtractCss = opts . css === false
@@ -201,12 +197,9 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin {
201197 }
202198 const isAllowed = createCustomBlockFilter ( opts . customBlocks || customBlocks )
203199
204- const beforeAssemble =
205- opts . beforeAssemble ||
206- ( ( d : DescriptorCompileResult ) : DescriptorCompileResult => d )
200+ const beforeAssemble = opts . beforeAssemble || ( ( d : DescriptorCompileResult ) : DescriptorCompileResult => d )
207201
208- const exposeFilename =
209- typeof opts . exposeFilename === 'boolean' ? opts . exposeFilename : false
202+ const exposeFilename = typeof opts . exposeFilename === 'boolean' ? opts . exposeFilename : false
210203
211204 const data : VuePluginOptionsData = ( opts . data || { } ) as any
212205
@@ -226,9 +219,9 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin {
226219 video : [ 'src' , 'poster' ] ,
227220 source : 'src' ,
228221 img : 'src' ,
229- image : 'xlink:href'
222+ image : 'xlink:href' ,
230223 } ,
231- ...opts . template
224+ ...opts . template ,
232225 } as any
233226
234227 if ( opts . template && typeof opts . template . isProduction === 'undefined' ) {
@@ -240,16 +233,11 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin {
240233
241234 if ( opts . css === false ) d ( 'Running in CSS extract mode' )
242235
243- function prependStyle (
244- id : string ,
245- lang : string ,
246- code : string ,
247- map : any
248- ) : { code : string } {
236+ function prependStyle ( id : string , lang : string , code : string , map : any ) : { code : string } {
249237 if ( ! ( lang in data ) ) return { code }
250238 const ms = new MagicString ( code , {
251239 filename : id ,
252- indentExclusionRanges : [ ]
240+ indentExclusionRanges : [ ] ,
253241 } )
254242
255243 const value : string | ( ( ) => string ) = ( data as any ) [ lang ]
@@ -282,7 +270,7 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin {
282270 return path . resolve ( path . dirname ( ref . filename ) , src as string )
283271 } else {
284272 return require . resolve ( src , {
285- paths : [ path . dirname ( ref . filename ) ]
273+ paths : [ path . dirname ( ref . filename ) ] ,
286274 } )
287275 }
288276 }
@@ -324,35 +312,22 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin {
324312 compiler : opts . compiler || templateCompiler ,
325313 compilerParseOptions : opts . compilerParseOptions ,
326314 sourceRoot : opts . sourceRoot ,
327- needMap : 'needMap' in opts ? ( opts as any ) . needMap : true
315+ needMap : 'needMap' in opts ? ( opts as any ) . needMap : true ,
328316 } )
329317 )
330318 )
331319
332320 descriptors . set ( filename , descriptor )
333321
334- const scopeId =
335- 'data-v-' +
336- ( isProduction
337- ? hash ( path . basename ( filename ) + source )
338- : hash ( filename + source ) )
322+ const scopeId = 'data-v-' + ( isProduction ? hash ( path . basename ( filename ) + source ) : hash ( filename + source ) )
339323
340324 const styles = await Promise . all (
341325 descriptor . styles . map ( async style => {
342326 if ( style . content ) {
343- style . content = prependStyle (
344- filename ,
345- style . lang || 'css' ,
346- style . content ,
347- style . map
348- ) . code
327+ style . content = prependStyle ( filename , style . lang || 'css' , style . content , style . map ) . code
349328 }
350329
351- const compiled = await compiler . compileStyleAsync (
352- filename ,
353- scopeId ,
354- style
355- )
330+ const compiled = await compiler . compileStyleAsync ( filename , scopeId , style )
356331 if ( compiled . errors . length > 0 ) throw Error ( compiled . errors [ 0 ] )
357332 return compiled
358333 } )
@@ -361,14 +336,11 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin {
361336 const input : any = {
362337 scopeId,
363338 styles,
364- customBlocks : [ ]
339+ customBlocks : [ ] ,
365340 }
366341
367342 if ( descriptor . template ) {
368- input . template = compiler . compileTemplate (
369- filename ,
370- descriptor . template
371- )
343+ input . template = compiler . compileTemplate ( filename , descriptor . template )
372344
373345 input . template . code = transformRequireToImport ( input . template . code )
374346
@@ -384,29 +356,17 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin {
384356 input . script = descriptor . script
385357 ? {
386358 code : `
387- export * from '${ createVuePartRequest (
388- filename ,
389- descriptor . script . lang || 'js' ,
390- 'script'
391- ) } '
392- import script from '${ createVuePartRequest (
393- filename ,
394- descriptor . script . lang || 'js' ,
395- 'script'
396- ) } '
359+ export * from '${ createVuePartRequest ( filename , descriptor . script . lang || 'js' , 'script' ) } '
360+ import script from '${ createVuePartRequest ( filename , descriptor . script . lang || 'js' , 'script' ) } '
397361 export default script
398362 ${
399363 exposeFilename
400364 ? `
401365 // For security concerns, we use only base name in production mode. See https://github.com/vuejs/rollup-plugin-vue/issues/258
402- script.__file = ${
403- isProduction
404- ? JSON . stringify ( path . basename ( filename ) )
405- : JSON . stringify ( filename )
406- } `
366+ script.__file = ${ isProduction ? JSON . stringify ( path . basename ( filename ) ) : JSON . stringify ( filename ) } `
407367 : ''
408368 }
409- `
369+ ` ,
410370 }
411371 : { code : '' }
412372
@@ -415,14 +375,7 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin {
415375 . map ( ( style : StyleCompileResult , index : number ) => {
416376 ; ( descriptor . styles [ index ] as any ) . code = style . code
417377
418- input . script . code +=
419- '\n' +
420- `import '${ createVuePartRequest (
421- filename ,
422- 'css' ,
423- 'styles' ,
424- index
425- ) } '`
378+ input . script . code += '\n' + `import '${ createVuePartRequest ( filename , 'css' , 'styles' , index ) } '`
426379
427380 if ( style . module || descriptor . styles [ index ] . scoped ) {
428381 return { ...style , code : '' , map : undefined }
@@ -449,32 +402,22 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin {
449402 ) } '`
450403 } )
451404
452- dT (
453- `id: ${ filename } \ncode:\n${ result . code } \n\nmap:\n${ JSON . stringify (
454- result . map ,
455- null ,
456- 2
457- ) } \n`
458- )
405+ dT ( `id: ${ filename } \ncode:\n${ result . code } \n\nmap:\n${ JSON . stringify ( result . map , null , 2 ) } \n` )
459406
460407 result . map = result . map || { mappings : '' }
461408
462409 return result
463410 }
464- }
411+ } ,
465412 }
466413}
467414
468- function createCustomBlockFilter (
469- customBlocks ?: string [ ] | ( ( tag : string ) => boolean )
470- ) : ( tag : string ) => boolean {
415+ function createCustomBlockFilter ( customBlocks ?: string [ ] | ( ( tag : string ) => boolean ) ) : ( tag : string ) => boolean {
471416 if ( typeof customBlocks === 'function' ) return customBlocks
472417 if ( ! Array . isArray ( customBlocks ) ) return ( ) => false
473418
474419 const allowed = new Set ( customBlocks . filter ( tag => ! tag . startsWith ( '!' ) ) )
475- const notAllowed = new Set (
476- customBlocks . filter ( tag => tag . startsWith ( '!' ) ) . map ( tag => tag . substr ( 1 ) )
477- )
420+ const notAllowed = new Set ( customBlocks . filter ( tag => tag . startsWith ( '!' ) ) . map ( tag => tag . substr ( 1 ) ) )
478421
479422 return tag => {
480423 if ( allowed . has ( tag ) ) return true
0 commit comments