benjaminkott / bootstrap_package

Bootstrap Package delivers a full configured theme for TYPO3, based on the Bootstrap CSS Framework.
https://www.bootstrap-package.com/
MIT License
338 stars 205 forks source link

Compile SCSS added through AssetCollector #1487

Open ww-ysg opened 5 months ago

ww-ysg commented 5 months ago

Compile SCSS added through AssetCollector

Is your feature request related to a problem? Please describe

In TYPO3 Version 10 the AssetCollector was introduced. It offers an easy way to include JavaScript and CSS Files. It would be great if SCSS Files included by the AssetCollector will be compiled just like SCSS Files included in TypoScript right now.

Describe the solution you'd like

With the AssetCollector the Event BeforeStylesheetsRenderingEvent was introduced, which could be used to compile the SCSS File. A possible Implementation could look like this:

public function __invoke(
        BeforeStylesheetsRenderingEvent $event,
    ): void {
        if(ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
            $assetCollector = $event->getAssetCollector();
            $stylesheets = $assetCollector->getStyleSheets();
            foreach ($stylesheets as $identifier => $stylesheet) {
                if(isset($stylesheet['source'])) {
                    if(str_contains($stylesheet['source'], 'EXT:')) {
                        $compiledFile = $this->compileService->getCompiledFile($GLOBALS['TYPO3_REQUEST'], $stylesheet['source']);
                        if($compiledFile) {
                            $assetCollector->addStyleSheet($identifier, $compiledFile);
                        }
                    }
                }
            }
        }
    }