Sass在使用”–style compressed”标志时,即使在逗号周围也会添加额外的空格。

huangapple go评论70阅读模式
英文:

Sass adds extra white spaces around commas even when using the "--style compressed" flag

问题

如何删除这些空格?

英文:

I have written a simple function to write multiple text-shadows and it's working fine.

@function text-shadow (
	$x: 0,
	$y: 0,
	$blur-radius: 0,
	$color: #000,
	$step: 0,
	$count: 1
) {

	$shadow: null;
	$_sum-step: 0;

	@for $i from 1 through $count {
		$_sum-step: $_sum-step + $step;
		$shadow: $shadow #{$x + $_sum-step} #{$y + $_sum-step} $blur-radius $color#{if($i != $count, ",", "")};
	}

	@return $shadow;
}

.long-shadow {
	color: #666;
	font-size: 100px;
	font-family: Arial;
	font-weight: 900;
	padding: 0 0 12px 0;
	text-shadow: text-shadow(
		$x: 0px,
		$y: 0px,
		$color: #ccc,
		$step: .5px,
		$count: 60
	);
}

I am generating the output CSS using:

sass --watch long-sh.scss:long-sh.css --style compressed

But, the output CSS file contains:

... text-shadow:0.5px 0.5px 0 #ccc , 1px 1px 0 #ccc , 1.5px 1.5px 0 #ccc , 2px 2px 0 #ccc , 2.5px 2.5px 0 #ccc , 3px 3px 0 #ccc , 3.5px 3.5px 0 #ccc , 4px 4px 0 #ccc , 4.5px 4.5px 0 #ccc , 5px 5px 0 #ccc , 5.5px 5.5px 0 #ccc , 6px 6px 0 #ccc , 6.5px 6.5px 0 #ccc , 7px 7px 0 #ccc , 7.5px 7.5px 0 #ccc , 8px 8px 0 #ccc , 8.5px 8.5px 0 #ccc , 9px 9px 0 #ccc , 9.5px 9.5px 0 #ccc , 10px 10px 0 #ccc , 10.5px 10.5px 0 #ccc , 11px 11px 0 #ccc , 11.5px 11.5px 0 #ccc , 12px 12px 0 #ccc , 12.5px 12.5px 0 #ccc , 13px 13px 0 #ccc , 13.5px 13.5px 0 #ccc , 14px 14px 0 #ccc , 14.5px 14.5px 0 #ccc , 15px 15px 0 #ccc , 15.5px 15.5px 0 #ccc , 16px 16px 0 #ccc , 16.5px 16.5px 0 #ccc , 17px 17px 0 #ccc , 17.5px 17.5px 0 #ccc , 18px 18px 0 #ccc , 18.5px 18.5px 0 #ccc , 19px 19px 0 #ccc , 19.5px 19.5px 0 #ccc , 20px 20px 0 #ccc , 20.5px 20.5px 0 #ccc , 21px 21px 0 #ccc , 21.5px 21.5px 0 #ccc , 22px 22px 0 #ccc , 22.5px 22.5px 0 #ccc , 23px 23px 0 #ccc , 23.5px 23.5px 0 #ccc , 24px 24px 0 #ccc , 24.5px 24.5px 0 #ccc , 25px 25px 0 #ccc , 25.5px 25.5px 0 #ccc , 26px 26px 0 #ccc , 26.5px 26.5px 0 #ccc , 27px 27px 0 #ccc , 27.5px 27.5px 0 #ccc , 28px 28px 0 #ccc , 28.5px 28.5px 0 #ccc , 29px 29px 0 #ccc , 29.5px 29.5px 0 #ccc , 30px 30px 0 #ccc}

where there are extra white spaces around the commas.

How can I remove these white spaces?

答案1

得分: 1

以下是翻译好的部分:

我个人可能不会花时间在这上面。

如果这对你很重要,尝试对压缩的 CSS 进行一些后处理,创建一个 Node 脚本,读取压缩文件,然后进行处理并写回文件。

这个简单的脚本接受一个字符串,并使用正则表达式去除逗号周围的空白。

英文:

I would probably not spend time on it personally.

If it's important to you try doing some postprocessing of your compressed css, create a node script and read the compressed file and then process it and write back to it.

This little simple script takes a string and uses regex to remove whitespaces around commas.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const testCss = &quot;text-shadow:0.5px 0.5px 0 #ccc , 1px 1px 0 #ccc , 1.5px 1.5px 0 #ccc , 2px 2px 0 #ccc , 2.5px 2.5px 0 #ccc , 3px 3px 0 #ccc , 3.5px 3.5px 0 #ccc , 4px 4px 0 #ccc , 4.5px 4.5px 0 #ccc , 5px 5px 0 #ccc , 5.5px 5.5px 0 #ccc , 6px 6px 0 #ccc , 6.5px 6.5px 0 #ccc , 7px 7px 0 #ccc , 7.5px 7.5px 0 #ccc , 8px 8px 0 #ccc , 8.5px 8.5px 0 #ccc , 9px 9px 0 #ccc , 9.5px 9.5px 0 #ccc , 10px 10px 0 #ccc , 10.5px 10.5px 0 #ccc , 11px 11px 0 #ccc , 11.5px 11.5px 0 #ccc , 12px 12px 0 #ccc , 12.5px 12.5px 0 #ccc , 13px 13px 0 #ccc , 13.5px 13.5px 0 #ccc , 14px 14px 0 #ccc , 14.5px 14.5px 0 #ccc , 15px 15px 0 #ccc , 15.5px 15.5px 0 #ccc , 16px 16px 0 #ccc , 16.5px 16.5px 0 #ccc , 17px 17px 0 #ccc , 17.5px 17.5px 0 #ccc , 18px 18px 0 #ccc , 18.5px 18.5px 0 #ccc , 19px 19px 0 #ccc , 19.5px 19.5px 0 #ccc , 20px 20px 0 #ccc , 20.5px 20.5px 0 #ccc , 21px 21px 0 #ccc , 21.5px 21.5px 0 #ccc , 22px 22px 0 #ccc , 22.5px 22.5px 0 #ccc , 23px 23px 0 #ccc , 23.5px 23.5px 0 #ccc , 24px 24px 0 #ccc , 24.5px 24.5px 0 #ccc , 25px 25px 0 #ccc , 25.5px 25.5px 0 #ccc , 26px 26px 0 #ccc , 26.5px 26.5px 0 #ccc , 27px 27px 0 #ccc , 27.5px 27.5px 0 #ccc , 28px 28px 0 #ccc , 28.5px 28.5px 0 #ccc , 29px 29px 0 #ccc , 29.5px 29.5px 0 #ccc , 30px 30px 0 #ccc}&quot;;
const removeWhitespace = (css) =&gt; {
const regex = /\s,\s/g;
return css.replace(regex, &#39;,&#39;);
}
console.log(removeWhitespace(testCss));

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月12日 14:38:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76454110.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定