Can I send Symfony parameter on Webpack Encore?

Viewed 535

I use Symfony 5 and Webpack Encore Bundle.

In my services.yaml, I have a list of colors :

parameters:
    colors:
        Beige: '#fffac8'
        Blue: '#0082c8'
        Black: '#000000'
        ...

These colors are used in a Command file, in my Controllers (= each user can choose a color), etc.

Is it possible to retrieve the colors parameter in my SCSS files generated by Webpack Encore Bundle, to avoid duplicating the code ?

Currently, I duplicate the colors of services.yaml directly in my scss file :

$beige: #fffac8;
$blue: #0082c8;
$black: #000000;

$theme-colors: (
    "beige": $beige,
    "blue": $blue,
    "black": $black,
    ...
1 Answers

You can declare your parameters into a JSON file and import it from your services.yaml and from your variables.scss with tools like sass-json-vars (or node-sass-json-importer for node-sass and webpack).

Or you can parse your scss file from PHP, injecting a custom dependency injection configuration loader, but I don't know any tools to do this.

In any case it's not properly a bullet-proof solution.

Related