-
-
Notifications
You must be signed in to change notification settings - Fork 199
css module issue #626
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
Comments
What about using |
I wasn't aware of this notation, but it dos not change anything. |
I'm trying to use CSS modules with Encore, but I got stuck here. I have a component like this: import React from 'react'
import style from '@style/Component.module.css?module'
const Component = () => <section className={style.section}><Stuff /></section>
export default Component While in my // ...
Encore
// ...
.enableSassLoader(() => ({ resolveUrlLoader: false }))
// ...
// alias to @style which is working correctly
// ... Am I missing something? |
Eventually I opted for something like this: import style from '!!style-loader!css-loader?modules!@style/Component.module.css' But I would prefer to update my webpack config in order to avoid the verbose import in every file. |
@nicolalamacchia If you want to enable modules globally you can probably do it using: Encore.configureCssLoader(options => {
options.modules = true;
}); Not sure why it doesn't work when importing something like webpack-encore/lib/config-generator.js Lines 263 to 277 in a4ae7ce
|
I cannot use |
@nicolalamacchia Are you using a recent version of Encore? Modules seem to work properly with the following setup: // webpack.config.js
const Encore = require('@symfony/webpack-encore');
const path = require('path');
Encore
.cleanupOutputBeforeBuild()
.setOutputPath('build/')
.setPublicPath('/build')
.addEntry('app', './assets/js/app.js')
.enableSingleRuntimeChunk()
.addAliases({
'@style': path.resolve('./assets/css')
})
;
module.exports = Encore.getWebpackConfig(); // assets/js/app.js
import style from '@style/app.css?module';
console.log(style); /* assets/css/app.css */
.foo {
background: #ff0000;
}
.bar {
color: white;
} Generated files: /* build/app.css */
.foo_25gLR{background:red}.bar_3FvIL{color:#fff} // build/app.js
(window.webpackJsonp=window.webpackJsonp||[]).push([["app"],{PhA5:function(o,n,s){o.exports={foo:"foo_25gLR",bar:"bar_3FvIL"}},ng4s:function(o,n,s){"use strict";s.r(n);var p=s("PhA5"),a=s.n(p);console.log(a.a)}},[["ng4s","runtime"]]]) |
Hi, I had some similar issue (?module not working with jest ) and fixed it with something like that (with Webpack Encore) : .configureCssLoader(options => { |
@rmaury I have a similar problem with jest, unfortunately adding your code does not help, can you please add the whole config wepback encore + jest here? |
Sorry for the delay Yes of course,
A custom.module.sass in a sass folder @import 'variables'
A custom.module.sass.ts in the same folder
And in you component you can now import like that :
Et voilà. Now, You should be able to import your component in Jest file without error. Just in case, for my project this is my jest.config.js
And my tsconfig.json
|
Thank you for this issue. |
1 similar comment
Thank you for this issue. |
Yes :)
Le jeu. 15 mai 2025 à 14:34, Carson: The Issue Bot ***@***.***>
a écrit :
… *carsonbot* left a comment (symfony/webpack-encore#626)
<#626 (comment)>
Thank you for this issue.
There has not been a lot of activity here for a while. Has this been
resolved?
—
Reply to this email directly, view it on GitHub
<#626 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJJ2NBZVLRXQDI34TKJ2WD26SCT3AVCNFSM6AAAAABRYZKCLWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQOBTGY2TQNJTG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Romain MAURY
+33(0)6 45 45 03 17 <+33(0)6+45+45+03+17> / ***@***.***
--
Ce message et toutes les pièces jointes (ci-après le "message") sont
confidentiels et établis à l'intention exclusive de ses destinataires.
Toute utilisation ou diffusion non autorisée est interdite. Tout
message étant susceptible d'altération, l'émetteur décline toute
responsabilité au titre de ce message s'il a été altéré, déformé ou
falsifié.
-----------------------------------
This message and any attachments (the "message") are confidential and
intended solely for the addressees. Any unauthorised use or
dissemination is prohibited. As e-mails are susceptible to alteration,
the issuer shall not be liable for the message if altered, changed
or falsified.
|
Uh oh!
There was an error while loading. Please reload this page.
Hello.
I can't get css module fully working in my React app.
The problem is that it only works if I use the
:local(.myClassName)
notation in my .scss filesHere's a js sample
Here's a scss sample
And the generated dom (no class tag)
Here is my webpack.config.js
The text was updated successfully, but these errors were encountered: