Webpack-encore: Empty object when importing css

Created on 7 Oct 2018  路  4Comments  路  Source: symfony/webpack-encore

Hi, I want to import a css file "css-modules way" but when I do this I got an empty object.

import test from './test.scss' // test == {}

question

All 4 comments

Hi @luxferoo,

Could you try this?

Encore.configureCssLoader(config => {
    config.modules = true;
});

@Lyrkan Hello my friend, Encore.configureCssLoader is not a recognized property or method

Oh, my bad I just noticed that it hasn't been released yet (added in #335), for some reason I thought it was way older than that.

So... currently there is no "easy" way to do it.
You can still modify the generated Webpack config object though, doing something like this should work:

const Encore = require('@symfony/webpack-encore');

Encore
    .setOutputPath('public/build/')
    .setPublicPath('/build')
    // (...)
;

// Retrieve the config object
const config = Encore.getWebpackConfig();

// Set "modules" option of the css-loader
for (const rule of config.module.rules) {
    if (rule.use) {
        for (const ruleUse of rule.use) {
            if (ruleUse.loader === 'css-loader') {
                ruleUse.options.modules = true;
            }
        }
    }
}

// Export the config (don't call getWebpackConfig() again)
module.exports = config;

@Lyrkan thanks buddy !

Was this page helpful?
0 / 5 - 0 ratings