diff --git a/packages/cli/src/plugins/resource/plugin-standard-css.js b/packages/cli/src/plugins/resource/plugin-standard-css.js index 63c3b74ba..c4c0ed9af 100644 --- a/packages/cli/src/plugins/resource/plugin-standard-css.js +++ b/packages/cli/src/plugins/resource/plugin-standard-css.js @@ -136,11 +136,18 @@ function bundleCss(body, url, compilation) { } else if (type === 'PseudoElementSelector') { optimizedCss += `::${name}`; } else if (type === 'MediaQuery') { - // TODO modifier seems to be null - // https://github.com/csstree/csstree/issues/285 + // https://github.com/csstree/csstree/issues/285#issuecomment-2350230333 const { mediaType, modifier } = node; - - optimizedCss += `${mediaType} ${modifier ?? 'and'}`; + const type = mediaType !== null + ? mediaType + : ''; + const operator = mediaType && node.condition + ? ' and' + : modifier !== null + ? ` ${modifier}` + : ''; + + optimizedCss += `${type}${operator}`; } else if (type === 'Block') { optimizedCss += '{'; } else if (type === 'AttributeSelector') { diff --git a/packages/cli/test/cases/build.config.optimization-default/fixtures/expected.css b/packages/cli/test/cases/build.config.optimization-default/fixtures/expected.css index 0e265be46..c311a63c3 100644 --- a/packages/cli/test/cases/build.config.optimization-default/fixtures/expected.css +++ b/packages/cli/test/cases/build.config.optimization-default/fixtures/expected.css @@ -80,4 +80,6 @@ tabbed-custom-element::part(tab){color:#0c0dcc;border-bottom:transparent solid 2 ::highlight(rainbow-color-1){color:#ad26ad;text-decoration:underline;} -h2{& span{color:red}} \ No newline at end of file +h2{& span{color:red}} + +@media (max-width:768px){span{flex-direction:column;text-align:center;}} \ No newline at end of file diff --git a/packages/cli/test/cases/build.config.optimization-default/src/styles/main.css b/packages/cli/test/cases/build.config.optimization-default/src/styles/main.css index dde456cbf..a8fb5f935 100644 --- a/packages/cli/test/cases/build.config.optimization-default/src/styles/main.css +++ b/packages/cli/test/cases/build.config.optimization-default/src/styles/main.css @@ -179,4 +179,11 @@ h2 { & span { color: red; } +} + +@media (max-width: 768px) { + span { + flex-direction: column; + text-align: center; + } } \ No newline at end of file