@@ -110,6 +110,9 @@ module.exports = class Breakpoints {
110110 if ( ! this . #config. drupal ?. themeName ) {
111111 console . warn ( MESSAGES . defaultThemeName ( ) ) ;
112112 }
113+ if ( ! this . #config. css . customMedia && ! this . #config. css . customProperty ) {
114+ console . warn ( MESSAGES . noCSSOutput ( ) ) ;
115+ }
113116 return true ;
114117 }
115118
@@ -217,20 +220,38 @@ module.exports = class Breakpoints {
217220 * @async
218221 */
219222 async #generateAndWriteCSS( ) {
223+ if ( ! this . #config. css . enabled ) {
224+ return ;
225+ }
226+ if ( ! this . #config. css . customMedia && ! this . #config. css . customProperty ) {
227+ return ;
228+ }
220229 const filePath = path . resolve ( process . cwd ( ) , this . #config. css . path ) ;
221- let string = "" ;
222- this . #customProperties. forEach ( ( customProperty ) => {
223- string += `--${ customProperty . identifier } : "${ customProperty . value } ";` ;
224- } ) ;
225230 const prettierConfig = {
226231 ...( this . #config. prettier ?. configPath
227232 ? await Breakpoints . getPrettierConfig ( this . #config. prettier . configPath )
228233 : { } ) ,
229234 parser : "css" ,
230235 } ;
236+ let string = "" ;
237+ if ( this . #config. css . customMedia ) {
238+ this . #customProperties. forEach ( ( customProperty ) => {
239+ // For syntax see postcss-custom-media plugin or W3C draft
240+ // Ref: https://www.npmjs.com/package/postcss-custom-media
241+ // Ref: https://www.w3.org/TR/mediaqueries-5/#at-ruledef-custom-media
242+ string += `@custom-media --${ customProperty . identifier } (${ customProperty . value } );` ;
243+ } ) ;
244+ }
245+ if ( this . #config. css . customProperty ) {
246+ string += `${ this . #config. css . element } {` ;
247+ this . #customProperties. forEach ( ( customProperty ) => {
248+ string += `--${ customProperty . identifier } : "${ customProperty . value } ";` ;
249+ } ) ;
250+ string += `}` ;
251+ }
231252 await Breakpoints . writeFile (
232253 filePath ,
233- prettier . format ( ` ${ this . #config . css . element } { ${ string } }` , prettierConfig )
254+ prettier . format ( string , prettierConfig )
234255 ) ;
235256 }
236257
0 commit comments