Git Product home page Git Product logo

Comments (4)

rossmc avatar rossmc commented on May 18, 2024

Hi @markopredovic,

I haven't done this myself in PWA Studio yet but imagine you will need to:

Install the webpack sass-loader:
https://github.com/webpack-contrib/sass-loader

And update the webpack.config.js file to include something like.

config.module.rules.push({
        test: /\.scss$/,
        loaders: [
            require.resolve('style-loader'),
            {
                loader: require.resolve('css-loader'),
                options: {
                    localIdentName: '[path][name]__[local]--[hash:base64:5]',
                    modules: true,
                },
            },
            {
                loader: require.resolve('sass-loader'),
                /**
                 * To prevent including the theme in every file we use the prependData attribute to load the theme
                 */
                options: {
                    prependData: '@import "./src/theme.scss";',
                },
            },
        ],
    });

For more info see:
https://magento.github.io/pwa-studio/technologies/basic-concepts/css-modules/

Once you getting it working, it would be great if you could share it in a PR.

Thanks :)

from how-to-venia.

markopredovic avatar markopredovic commented on May 18, 2024

Thanks @rossmc , will do

from how-to-venia.

markopredovic avatar markopredovic commented on May 18, 2024

I ended with this configuration for now, it is not quite generic but ok, scss files with 'module' in name are scoped to component, also have global available scss styles in src root directory.

clientConfig.module.rules.push(
        {
            test: /\.module\.s(a|c)ss$/,
            loaders: [
                require.resolve('style-loader'),
                {
                    loader: require.resolve('css-loader'),
                    options: {
                        localIdentName:
                            '[path][name]__[local]--[hash:base64:5]',
                        modules: true
                    }
                },
                {
                    loader: require.resolve('sass-loader')
                    /**
                     * To prevent including the theme in every file we use the prependData attribute to load the theme
                     */
                }
            ]
        },
        {
            test: /s(a|c)ss$/,
            exclude: /\.module.(s(a|c)ss)$/,
            loaders: [
                require.resolve('style-loader'),
                {
                    loader: require.resolve('css-loader')
                },
                {
                    loader: require.resolve('sass-loader'),
                    /**
                     * To prevent including the theme in every file we use the prependData attribute to load the theme
                     */
                    options: {
                        prependData: '@import "./src/styles/styles.scss";'
                    }
                }
            ]
        }
    );

from how-to-venia.

rossmc avatar rossmc commented on May 18, 2024

oh this is great. Thanks @markopredovic.

At some point soon, I hope use this to update the css-modules doc with an Optionally Use SCSS section.

from how-to-venia.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.