Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty object when importing css #402

Closed
luxferoo opened this issue Oct 7, 2018 · 4 comments
Closed

Empty object when importing css #402

luxferoo opened this issue Oct 7, 2018 · 4 comments
Labels

Comments

@luxferoo
Copy link

luxferoo commented Oct 7, 2018

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 == {}

@Lyrkan
Copy link
Collaborator

Lyrkan commented Oct 7, 2018

Hi @luxferoo,

Could you try this?

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

@Lyrkan Lyrkan added the question label Oct 7, 2018
@luxferoo
Copy link
Author

luxferoo commented Oct 7, 2018

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

@Lyrkan
Copy link
Collaborator

Lyrkan commented Oct 7, 2018

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;

@luxferoo
Copy link
Author

luxferoo commented Oct 7, 2018

@Lyrkan thanks buddy !

@Lyrkan Lyrkan closed this as completed Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants