From b7791c4335808a340a7dac7111c633fc188fa3e2 Mon Sep 17 00:00:00 2001 From: raivaibhav Date: Sat, 9 Oct 2021 17:21:53 +0530 Subject: [PATCH] Add minification for media queries --- src/compiler/compile/css/Stylesheet.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/compiler/compile/css/Stylesheet.ts b/src/compiler/compile/css/Stylesheet.ts index fcc0e6481d..c4b7105021 100644 --- a/src/compiler/compile/css/Stylesheet.ts +++ b/src/compiler/compile/css/Stylesheet.ts @@ -221,13 +221,7 @@ class Atrule { const expression_char = code.original[this.node.prelude.start]; let c = this.node.start + (expression_char === '(' ? 6 : 7); - // code.overwrite(this.node.start, this.node.prelude.start, '@media '); - if (format) { - // Add space before the prelude - overwrite(code, c, this.node.prelude.start, ' '); - } else if (this.node.prelude.start > c) { - code.remove(c, this.node.prelude.start); - } + if (this.node.prelude.start > c) code.remove(c, this.node.prelude.start); this.node.prelude.children.forEach((query: CssNode) => { // TODO minify queries @@ -320,6 +314,17 @@ class Atrule { if (this.node.prelude) { walk(this.node.prelude.children as any, { enter: (node: any, parent: any) => { + if (node.type === 'MediaQuery') { + let c = node.start; + node.children.forEach((child: any, i: number) => { + if (child.type !== 'WhiteSpace') { + if (i > 0) { + code.overwrite(c, child.start, ' '); + } + c = child.end; + } + }); + } if (parent && parent.type === 'MediaFeature') { const char_at_start = code.original[parent.start]; const char_at_end = code.original[parent.end - 1];