css-crush icon indicating copy to clipboard operation
css-crush copied to clipboard

Migration from Less - handling of double slash comments

Open chrisdeeming opened this issue 1 year ago • 2 comments

This isn't a dealbreaker, but thought I'd ask the question.

// avatars
.avatar
{
    // overflow: hidden;
    border-radius: var(--radius-avatar, 100vw);
}

With Less, this would be output as:

.avatar
{
    border-radius: var(--radius-avatar, 100vw);
}

It looks like we can use the declaration_preprocess event to strip out properties that start with //.

Are there any events that would enable us to strip out the others, or convert them to CSS comments?

chrisdeeming avatar Mar 08 '24 11:03 chrisdeeming

This works, I guess?

$process->on('capture_phase0', function (\CssCrush\Process $process)
{
	$process->input->string = preg_replace('/^\s*\/\/.*/m', '', $process->input->string);
	$importer = new \CssCrush\Importer($process);
	$process->string = new \CssCrush\StringObject($importer->collate());
});

We're probably just going to pre-process the template before passing it to crush. Though this highlights that perhaps an event that allows you to modify the input could be useful for others.

chrisdeeming avatar Mar 08 '24 11:03 chrisdeeming

This preprocessor only handles the comment style standard to CSS /* */, as staying close to the standard is a design goal

peteduel avatar Mar 08 '24 14:03 peteduel