Skip to content

CSS Modules #229

@Sydney-o9

Description

@Sydney-o9

CSS Modules - question

Is there any way to have CSS Modules working with Symfony Encore using Twig?

I would assume this is pretty straight forward to setup with React frontend, but if people use twig, would there be a way to use CSS Modules?

I am not sure how to or if this is even possible, but just raising the question because I think frontend becomes a lot more maintainable with CSS modules..

I personally tend to use CSS Modules in all isomorphic js projects but would love to use it with Symfony Encore & Twig. I think it would be amazing.


For example, if we were to:

1 Import our css

{% block stylesheets %}
    {{ parent() }}
    <link rel="stylesheet" href="{{ asset('build/business/register.css') data-css-modules="mycss" }}">
{% endblock %}

2 Reference our classes with mycss

<h1 class="{{ header | css_modules('mycss') }}">Title</h1>

Twig could generate a unique hash per file imported and Webpack with Symfony Encore would then use the same unique hash.

This is just an idea, again.. just to see what you smart people think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions