wapplersystems/ws-scss
Composer 安装命令:
composer require wapplersystems/ws-scss
包简介
Compiles SCSS to CSS at runtime with caching, TypoScript variables and EXT: import support
README 文档
README
Compiles SCSS files to CSS at runtime. Uses SCSSPHP as compiler. Compiled CSS is cached and only recompiled when source files or variables change.
Installation
composer require wapplersystems/ws-scss
Requirements
- TYPO3 v14
- PHP 8.2+
Usage via TypoScript
Include SCSS files with the standard page.includeCSS — the extension automatically compiles any .scss file:
page.includeCSS {
main = EXT:my_sitepackage/Resources/Private/Scss/main.scss
}
Custom output file
page.includeCSS {
bootstrap = fileadmin/bootstrap/sass/bootstrap.scss
bootstrap.outputfile = fileadmin/bootstrap/css/mybootstrap.css
}
Output style
compressed (default) or expanded:
page.includeCSS {
main = EXT:my_sitepackage/Resources/Private/Scss/main.scss
main.outputStyle = expanded
}
Source maps
Enables SCSS file/line references in browser DevTools:
page.includeCSS {
main = EXT:my_sitepackage/Resources/Private/Scss/main.scss
main.sourceMap = true
}
Inline output
Renders CSS inline in a <style> tag instead of a <link> reference:
page.includeCSS {
critical = EXT:my_sitepackage/Resources/Private/Scss/critical.scss
critical.inlineOutput = true
}
Variables
Global variables
Available in all SCSS files:
plugin.tx_wsscss.variables {
primaryColor = #007bff
secondaryColor = #6c757d
baseFontSize = 16px
}
Per-file variables
Override or extend global variables for a specific file:
page.includeCSS {
main = EXT:my_sitepackage/Resources/Private/Scss/main.scss
main.variables {
primaryColor = #ff6600
containerWidth = 1200px
}
}
Using variables in SCSS
Variables defined via TypoScript are directly available as SCSS variables:
body { color: $primaryColor; font-size: $baseFontSize; }
Variable type conversion
The extension automatically converts TypoScript values to proper SCSS types:
| TypoScript value | SCSS type |
|---|---|
#007bff |
Color (RGB) |
16px |
Number with px unit |
1.5rem |
Number with rem unit |
"Arial, sans-serif" |
String |
| Other values | Generic value |
SCSS imports
Standard SCSS imports work as expected. Additionally, the extension supports TYPO3's EXT: paths:
@import "variables"; @import "mixins"; @import "EXT:bootstrap/Resources/Public/Scss/bootstrap";
File resolution order: filename.scss, _filename.scss, filename.css.
Usage via Fluid ViewHelper
The extension registers a ViewHelper for compiling SCSS in Fluid templates.
File-based
<wsscss:asset.scss identifier="main" href="EXT:my_sitepackage/Resources/Private/Scss/main.scss" />
With variables
<wsscss:asset.scss identifier="styled" href="EXT:my_sitepackage/Resources/Private/Scss/styles.scss" scssVariables="{primaryColor: '#0066cc', borderRadius: '4px'}" />
Inline SCSS
<wsscss:asset.scss identifier="inline"> $color: red; body { background: $color; } </wsscss:asset.scss>
ViewHelper arguments
| Argument | Type | Required | Description |
|---|---|---|---|
identifier |
string | yes | Unique ID for asset deduplication |
href |
string | no | Path to SCSS file (EXT: or fileadmin/) |
scssVariables |
array | no | Variables to pass to the compiler |
outputfile |
string | no | Custom path for compiled CSS output |
forcedOutputLocation |
string | no | Force inline or file output |
priority |
bool | no | Load before other stylesheets |
disabled |
bool | no | Add disabled attribute |
Events
AfterVariableDefinitionEvent
Modify variables before compilation:
use WapplerSystems\WsScss\Event\AfterVariableDefinitionEvent; #[AsEventListener] final class AddDynamicVariables { public function __invoke(AfterVariableDefinitionEvent $event): void { $variables = $event->getVariables(); $variables['dynamicColor'] = '#ff0000'; $event->setVariables($variables); } }
AfterScssCompilationEvent
Post-process compiled CSS:
use WapplerSystems\WsScss\Event\AfterScssCompilationEvent; #[AsEventListener] final class PostProcessCss { public function __invoke(AfterScssCompilationEvent $event): void { $css = $event->getCssCode(); $css .= "\n/* Compiled at " . date('c') . " */"; $event->setCssCode($css); } }
Caching
Compiled CSS is cached in typo3temp/assets/css/. The cache is automatically invalidated when:
- SCSS source files change
- Imported files change
- Variables change
- Output style or source map settings change
To force recompilation, flush caches via backend or CLI:
vendor/bin/typo3 cache:flush --group=system
Development tip
Disable the TypoScript template cache in your backend user settings to trigger SCSS recompilation on every page load during development.
Complete example
plugin.tx_wsscss.variables {
brandColor = #0066cc
fontFamily = "Open Sans, sans-serif"
baseFontSize = 16px
}
page.includeCSS {
bootstrap = EXT:my_sitepackage/Resources/Private/Scss/bootstrap.scss
bootstrap.outputStyle = compressed
theme = EXT:my_sitepackage/Resources/Private/Scss/theme.scss
theme.outputStyle = compressed
theme.variables {
headerHeight = 80px
sidebarWidth = 300px
}
}
License
GPL-2.0-or-later
wapplersystems/ws-scss 适用场景与选型建议
wapplersystems/ws-scss 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 148.75k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2022 年 09 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「css」 「sass」 「scss」 「compiler」 「typo3」 「scssphp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wapplersystems/ws-scss 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wapplersystems/ws-scss 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wapplersystems/ws-scss 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
Zend Framework 3+ module that provides assets bundling / caching
bootstrap-sass is a Sass-powered version of Bootstrap 3, ready to drop right into your Sass powered applications.
Define your own css rule-sets for the TYPO3 CMS backend.
Laravel React Boilerplate
统计信息
- 总下载量: 148.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 23
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2022-09-17