@@ -37,34 +37,35 @@ export function cssImportPlugin() {
37
37
}
38
38
39
39
/** @return {import('@web/test-runner').TestRunnerPlugin } */
40
- export function enforceLegacyLumoPlugin ( ) {
40
+ export function enforceThemePlugin ( theme ) {
41
41
return {
42
- name : 'enforce-legacy-lumo ' ,
42
+ name : 'enforce-theme ' ,
43
43
transform ( context ) {
44
- if ( context . response . is ( 'js' , 'html' ) ) {
45
- return context . body
46
- . replaceAll (
47
- `import '@vaadin/vaadin-lumo-styles/global.css'` ,
48
- `import '@vaadin/vaadin-lumo-styles/test/autoload.js'` ,
49
- )
50
- . replaceAll ( / ^ .* @ v a a d i n \/ v a a d i n - l u m o - s t y l e s \/ .* \. c s s .* $ / gmu, '' ) ;
44
+ let { body } = context ;
45
+
46
+ if ( context . response . is ( 'html' ) && ( theme === 'base' || theme === 'ported-lumo' ) ) {
47
+ // Load the base theme
48
+ body = body . replace ( './common.js' , './common-base.js' ) ;
51
49
}
52
- } ,
53
- } ;
54
- }
55
50
56
- /** @return {import('@web/test-runner').TestRunnerPlugin } */
57
- export function enforceBaseStylesPlugin ( ) {
58
- return {
59
- name : 'enforce-base-styles' ,
60
- transform ( context ) {
61
- if ( context . response . is ( 'html' ) ) {
62
- return { body : context . body . replace ( './common.js' , './common-base.js' ) } ;
51
+ if ( context . response . is ( 'html' , 'js' ) && ( theme === 'base' || theme === 'legacy-lumo' ) ) {
52
+ // Remove all CSS imports
53
+ body = body . replaceAll ( / ^ .+ v a a d i n - l u m o - s t y l e s \/ .+ \. c s s .+ $ / gmu, '' ) ;
63
54
}
55
+
56
+ return body ;
64
57
} ,
65
58
transformImport ( { source } ) {
66
- source = source . replace ( '/theme/lumo/' , '/src/' ) ;
67
- source = source . replace ( / ( .+ ) - c o r e - s t y l e s \. j s / u, '$1-base-styles.js' ) ;
59
+ if ( theme === 'base' || theme === 'ported-lumo' ) {
60
+ // Load the base theme
61
+ source = source . replace ( '/theme/lumo/' , '/src/' ) ;
62
+ source = source . replace ( / ( .+ ) - c o r e - s t y l e s \. j s / u, '$1-base-styles.js' ) ;
63
+ }
64
+
65
+ if ( theme === 'legacy-lumo' ) {
66
+ source = source . replace ( 'vaadin-lumo-styles/global.css' , 'vaadin-lumo-styles/test/autoload.js' ) ;
67
+ }
68
+
68
69
return source ;
69
70
} ,
70
71
} ;
@@ -120,13 +121,13 @@ export default {
120
121
esbuildPlugin ( { ts : true } ) ,
121
122
122
123
// yarn start --theme=base
123
- theme === 'base' && enforceBaseStylesPlugin ( ) ,
124
+ theme === 'base' && enforceThemePlugin ( 'base' ) ,
124
125
125
126
// yarn start --theme=lumo (uses legacy lumo styles defined in js files)
126
- theme === 'lumo' && ! hasPortedParam && enforceLegacyLumoPlugin ( ) ,
127
+ theme === 'lumo' && ! hasPortedParam && enforceThemePlugin ( 'legacy-lumo' ) ,
127
128
128
129
// yarn start --theme=lumo --ported (uses base styles and lumo styles defined in css files)
129
- theme === 'lumo' && hasPortedParam && enforceBaseStylesPlugin ( ) ,
130
+ theme === 'lumo' && hasPortedParam && enforceThemePlugin ( 'ported-lumo' ) ,
130
131
theme === 'lumo' && hasPortedParam && cssImportPlugin ( ) ,
131
132
] . filter ( Boolean ) ,
132
133
} ;
0 commit comments