@@ -29,10 +29,11 @@ const { sync } = glob;
2929const themeComponentsFolder = 'components' ;
3030// The contents of a global CSS file with this name in a theme is always added to
3131// the document. E.g. @font-face must be in this
32- const documentCssFile = 'document.css' ;
32+ const documentCssFilename = 'document.css' ;
3333// styles.css is the only entrypoint css file with document.css. Everything else should be imported using css @import
34- const stylesCssFile = 'styles.css' ;
34+ const stylesCssFilename = 'styles.css' ;
3535
36+ const CSSIMPORT_COMMENT = 'CSSImport end' ;
3637const headerImport = `import 'construct-style-sheets-polyfill';
3738` ;
3839
@@ -48,8 +49,8 @@ const headerImport = `import 'construct-style-sheets-polyfill';
4849function generateThemeFile ( themeFolder , themeName , themeProperties , options ) {
4950 const productionMode = ! options . devMode ;
5051 const useDevServer = ! options . useDevBundle ;
51- const styles = resolve ( themeFolder , stylesCssFile ) ;
52- const document = resolve ( themeFolder , documentCssFile ) ;
52+ const styles = resolve ( themeFolder , stylesCssFilename ) ;
53+ const documentCssFile = resolve ( themeFolder , documentCssFilename ) ;
5354 const autoInjectComponents = themeProperties . autoInjectComponents ?? true ;
5455 let themeFile = headerImport ;
5556 var componentsFiles ;
@@ -73,7 +74,6 @@ function generateThemeFile(themeFolder, themeName, themeProperties, options) {
7374
7475 const imports = [ ] ;
7576 const globalCssCode = [ ] ;
76- const lumoCssCode = [ ] ;
7777 const lumoCssShadowOnlyCode = [ ] ;
7878 const componentCssCode = [ ] ;
7979 const parentTheme = themeProperties . parent ? 'applyBaseTheme(target);\n' : '' ;
@@ -97,12 +97,10 @@ function generateThemeFile(themeFolder, themeName, themeProperties, options) {
9797 // styles.css will always be available as we write one if it doesn't exist.
9898 let filename = basename ( styles ) ;
9999 let variable = camelCase ( filename ) ;
100- if ( useDevServer ) {
101- imports . push ( `import ${ variable } from 'themes/${ themeName } /${ filename } ?inline';\n` ) ;
102- }
103- /* Lumo must be first so that custom styles override Lumo styles */
100+
101+ /* LUMO */
104102 const lumoImports = themeProperties . lumoImports || [ 'color' , 'typography' ] ;
105- if ( lumoImports && lumoImports . length > 0 ) {
103+ if ( lumoImports ) {
106104 lumoImports . forEach ( ( lumoImport ) => {
107105 imports . push ( `import { ${ lumoImport } } from '@vaadin/vaadin-lumo-styles/${ lumoImport } .js';\n` ) ;
108106 if ( lumoImport === 'utility' || lumoImport === 'badge' ) {
@@ -113,20 +111,22 @@ function generateThemeFile(themeFolder, themeName, themeProperties, options) {
113111
114112 lumoImports . forEach ( ( lumoImport ) => {
115113 // Lumo is injected to the document by Lumo itself
116- lumoCssShadowOnlyCode . push ( `injectGlobalCss(${ lumoImport } .cssText, target, true);\n` ) ;
114+ lumoCssShadowOnlyCode . push ( `injectGlobalCss(${ lumoImport } .cssText, '', target, true);\n` ) ;
117115 } ) ;
118116 }
119117
118+ /* Theme */
120119 if ( useDevServer ) {
121- globalCssCode . push ( `injectGlobalCss(${ variable } .toString(), target);\n ` ) ;
120+ imports . push ( `import ${ variable } from 'themes/${ themeName } /${ filename } ?inline';\n` ) ;
121+ globalCssCode . push ( `injectGlobalCss(${ variable } .toString(), '', target);\n ` ) ;
122122 }
123- if ( existsSync ( document ) ) {
124- filename = basename ( document ) ;
123+ if ( existsSync ( documentCssFile ) ) {
124+ filename = basename ( documentCssFile ) ;
125125 variable = camelCase ( filename ) ;
126126
127127 if ( useDevServer ) {
128128 imports . push ( `import ${ variable } from 'themes/${ themeName } /${ filename } ?inline';\n` ) ;
129- globalCssCode . push ( `injectGlobalCss(${ variable } .toString(), document);\n ` ) ;
129+ globalCssCode . push ( `injectGlobalCss(${ variable } .toString(),'', document);\n ` ) ;
130130 }
131131 }
132132
@@ -147,9 +147,9 @@ function generateThemeFile(themeFolder, themeName, themeProperties, options) {
147147 // Due to chrome bug https://bugs.chromium.org/p/chromium/issues/detail?id=336876 font-face will not work
148148 // inside shadowRoot so we need to inject it there also.
149149 globalCssCode . push ( `if(target !== document) {
150- injectGlobalCss(${ variable } .toString(), target);
150+ injectGlobalCss(${ variable } .toString(), '', target);
151151 }\n ` ) ;
152- globalCssCode . push ( `injectGlobalCss(${ variable } .toString(), document);\n ` ) ;
152+ globalCssCode . push ( `injectGlobalCss(${ variable } .toString(), ' ${ CSSIMPORT_COMMENT } ', document);\n ` ) ;
153153 } ) ;
154154 }
155155 if ( themeProperties . importCss ) {
@@ -165,7 +165,7 @@ function generateThemeFile(themeFolder, themeName, themeProperties, options) {
165165 themeProperties . importCss . forEach ( ( cssPath ) => {
166166 const variable = 'module' + i ++ ;
167167 imports . push ( `import ${ variable } from '${ cssPath } ';\n` ) ;
168- globalCssCode . push ( `injectGlobalCss(${ variable } .toString(), target);\n` ) ;
168+ globalCssCode . push ( `injectGlobalCss(${ variable } .toString(), ' ${ CSSIMPORT_COMMENT } ', target);\n` ) ;
169169 } ) ;
170170 }
171171
@@ -191,10 +191,8 @@ function generateThemeFile(themeFolder, themeName, themeProperties, options) {
191191 // If targets check that we only register the style parts once, checks exist for global css and component css
192192 const themeFileApply = `export const applyTheme = (target) => {
193193 if (target !== document) {
194- // Lumo is injected to the document by Lumo itself, except for the utility module
195194 ${ lumoCssShadowOnlyCode . join ( '' ) }
196195 }
197- ${ lumoCssCode . join ( '' ) }
198196 ${ parentTheme }
199197 ${ globalCssCode . join ( '' ) }
200198
0 commit comments