@@ -167,17 +167,33 @@ export async function compileFile(
167167 )
168168 }
169169
170- if ( clientCode || ssrCode ) {
171- appendSharedCode (
172- `\n${ COMP_IDENTIFIER } .__file = ${ JSON . stringify ( filename ) } ` +
173- `\nexport default ${ COMP_IDENTIFIER } `
174- )
175- compiled . js = clientCode . trimStart ( )
176- compiled . ssr = ssrCode . trimStart ( )
170+ // styles
171+ const ceFilter = store . customElement
172+ function isCustomElement ( filters : typeof ceFilter ) : boolean {
173+ if ( typeof filters === 'boolean' ) {
174+ return filters
175+ }
176+
177+ if ( typeof filters === 'string' ) {
178+ return filters . includes ( filename )
179+ } else if (
180+ ! Array . isArray ( filters ) &&
181+ Object . prototype . toString . call ( filters ) === '[object RegExp]'
182+ ) {
183+ return filters . test ( filename )
184+ }
185+
186+ if ( Array . isArray ( filters ) ) {
187+ return filters . some ( ( filter ) => {
188+ return isCustomElement ( filter )
189+ } )
190+ }
191+ return false
177192 }
193+ let isCE = isCustomElement ( ceFilter )
178194
179- // styles
180195 let css = ''
196+ let styles : string [ ] = [ ]
181197 for ( const style of descriptor . styles ) {
182198 if ( style . module ) {
183199 return [ `<style module> is not supported in the playground.` ]
@@ -199,13 +215,27 @@ export async function compileFile(
199215 }
200216 // proceed even if css compile errors
201217 } else {
202- css += styleResult . code + '\n'
218+ isCE ? styles . push ( styleResult . code ) : ( css += styleResult . code + '\n' )
203219 }
204220 }
205221 if ( css ) {
206222 compiled . css = css . trim ( )
207223 } else {
208- compiled . css = '/* No <style> tags present */'
224+ compiled . css = isCE ? ( compiled . css = '/* The component style of the custom element will be compiled into the component object */' )
225+ : ( '/* No <style> tags present */' )
226+ }
227+
228+ if ( clientCode || ssrCode ) {
229+ const ceStyles = isCE
230+ ? `\n${ COMP_IDENTIFIER } .styles = ${ JSON . stringify ( styles ) } `
231+ : ''
232+ appendSharedCode (
233+ `\n${ COMP_IDENTIFIER } .__file = ${ JSON . stringify ( filename ) } ` +
234+ ceStyles +
235+ `\nexport default ${ COMP_IDENTIFIER } `
236+ )
237+ compiled . js = clientCode . trimStart ( )
238+ compiled . ssr = ssrCode . trimStart ( )
209239 }
210240
211241 return [ ]
0 commit comments