Sunsetting SCSS

未关闭
#6,044 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
停滞
技术栈
css, php, scss

调研方向

This issue is part of the broader style system overhaul in #6028. Read that initiative alongside this comparison of SCSS and native CSS, then map where SCSS compilation, variables, and generated stylesheets are used in the project. Done means the style system no longer depends on SCSS and supports the CSS delivery and development workflows described here.

由索引模型根据 Issue 内容生成。

描述

Discussion

Note: This is part of a larger initiative to overhaul the style system and the customization options in general. See #6028 to learn more.

CSS for the longest time was very static and most features focused on achieving new visual effects and layout options, with little to no progress towards the developer experience. CSS preprocessors like LESS or SASS/SCSS filled the gap by providing a single build step that provided a lot of features that ease the day-to-day work with large style codebases. However, CSS continued to evolve and provides a lot of native solutions for these problems today.

Comparison of CSS to Preprocessors Today

The following will use SCSS as the example and focused on the features currently used in our scenario.

Feature SCSS Native CSS Comment
Selector Nesting ✅ ✅ (Baseline 2023) Nesting selectors allowed to extend an existing selector without having to repeat the entire selector. Over time styles became more focused and component scoped, greatly reducing the need for this feature in the first place.
Dynamic Variables ❌ ✅ (Baseline) SCSS variables are replaced on compile time while CSS variables can change their value dynamically, for example, to change formatting based on the color scheme.
Functions ✅ ❌ SCSS functions allow to generate CSS based on parameters. Can be emulated to some degree with CSS variables and by manually creating the selectors.
Extending Selectors ✅ ❌ Existing selectors can be extended in SCSS which applies the same CSS rules without having to change the CSS classes in the DOM. Used only occasionally and can be replaced by proper CSS classes in the DOM instead. 
Deriving Values ✅ ✅ (Baseline 2024) Computing colors based on rules, for example, adding transparency to an existing color value. High potential for misuse by using effectively fixed values (like darken()) that fall apart for dark colors.
Variables for Media Queries ✅ ❌ It is currently not possible to replicate helper functions like @include screen-md-down in pure CSS without processing the CSS first. This means authors will have to manually copy the selector instead of using a handful of easily memorizable helpers. There is a draft for supporting this through env() but this might still be years away.
ACP Options to Toggle Behavior ✅ ✅ Certain options are exposed to the SCSS compiler as variables which allow for some degree of decision making when generating the CSS output. This can possibly be replicated by exporting these values as data attributes on the document/body element.
Auto-prefixing of selectors ✅  ❌  Replacement functions in SCSS allow to write standards-compliant CSS by automagically expanding it to vendor specific selectors. Historically this was a great feature but considering the ongoing “Baseline” initiative among all major browsers, this is a thing of the past.
Bundling of CSS files ✅ ❌ This can be achieved with very little code on our own and will be required for production. Being able to minify the CSS is nice but it’s unclear if it provides any meaningful advantage after gzip.
Swap out files for development ❌ ✅ CSS files can simply be swapped out on-the-fly for development purposes by loading all CSS files “the traditional way”. SCSS requires an extra compilation step to yield the updated CSS.
On-demand stylesheets ❌ ✅ SCSS compiles into one big blob, although it should be possible to create separate artifacts. CSS natively is modularized, allowing extra stylesheets to be conditionally included because there are no actual dependencies. Allows for a smaller base stylesheet.

Other Things to Consider

We’re currently using the legacy rgba(r, g, b, a) syntax to store color values. This works just fine but requires an extra step to allow for dynamic changes, for example, to create a gradient from a color value to its transparent variant (thanks Safari!). For this purpose we’re currently outputting an extra set of variables which only contain the r g b portion of the value.

We should investigate which format is best suited to work with CSS functions, including but not limited to different color formats in general.

Path Forward

Dropping the CSS preprocessors removes quite a large library from our dependencies which is also very computational expensive. Furthermore SCSS encourages certain patterns like derived values, nesting and extending of selectors that could be considered harmful.

CSS has matured so much over the past years, that it provides most building blocks for proper development out-of-the-box in every major browser. Most important, this allows us to finally ship with on-demand stylesheets and a development mode with support for swapping out CSS files on the go, for example, by simply uploading it to a server.

The lack of variables for media queries is quite annoying because the @include screen-* have proven to be easily memorizable as well as guaranteeing a consistent behavior. However, this is just a minor nuisance that does not justify the use of a heavy preprocessor.

主要语言
PHP
星标
248
派生
147
平均合并
17 分钟
30 天内合并 PR
21

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

WoltLab/WCF 的其他 Issue

查看 WoltLab/WCF 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。