@@ -167,17 +167,33 @@ export async function compileFile(
167
167
)
168
168
}
169
169
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
177
192
}
193
+ let isCE = isCustomElement ( ceFilter )
178
194
179
- // styles
180
195
let css = ''
196
+ let styles : string [ ] = [ ]
181
197
for ( const style of descriptor . styles ) {
182
198
if ( style . module ) {
183
199
return [ `<style module> is not supported in the playground.` ]
@@ -199,13 +215,27 @@ export async function compileFile(
199
215
}
200
216
// proceed even if css compile errors
201
217
} else {
202
- css += styleResult . code + '\n'
218
+ isCE ? styles . push ( styleResult . code ) : ( css += styleResult . code + '\n' )
203
219
}
204
220
}
205
221
if ( css ) {
206
222
compiled . css = css . trim ( )
207
223
} 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 ( )
209
239
}
210
240
211
241
return [ ]
0 commit comments