You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use postcss-modules to generate JSON mapping file that I'm using on the server (in PHP). But I also wanted to use CSS modules directly in my JS files like this:
import styles from './index.module.scss';
console.log(styles);
What I get from the JSON file, must be the same as styles. So let's say it should be for example (simplified):
I came across several problems and I feel like I'm running in circles:
If I leave it exactly like above, JSON file is correct but postcss-modules actually changes local name used in css-loader so styles looks something like this:
If I don't include modules option in css-loader, JSON file is correct but styles is an empty object.
If I omit postcss-modules, styles looks as desired but of course, no JSON file is generated, and I need this for server part.
Why does postcss-modules change local variable used in css-loader? Why is styles an empty object if I don't add modules options to css-loader? How can I combine both together?
The text was updated successfully, but these errors were encountered:
@samuelg0rd0n, I faced the same problem. This repo looks a bit abandoned. At the same time, maintainers of the css-loader do not consider it significant to implement the export of generated module names to JSON. So, for now, I decided to do this - generate modules using the postcss-loader, and then generate the modules in the css-loader with: localIdentName parameter: '[local]'
As a result I have modules, classes can be written in html using css-module = "" and the styles object is not empty. The only problem is that IDE does not suggest names, but with the help of a small function that selects using regexp, I can find in this object a hashed name by class name in css / scss if I use: generateScopedName: '[local] _ [hash: base64: 5 ]
in postсss-module.
The initial class name is stored hashed in this case. This is necessary for a possibility to find the new class name in js. But, the main, as I think, hashing function of modules is working in this case - no problems with name conflicts.
I use postcss-modules to generate JSON mapping file that I'm using on the server (in PHP). But I also wanted to use CSS modules directly in my JS files like this:
What I get from the JSON file, must be the same as
styles
. So let's say it should be for example (simplified):My webpack.config.js currently looks something like this (simplified):
I came across several problems and I feel like I'm running in circles:
If I leave it exactly like above, JSON file is correct but postcss-modules actually changes
local
name used in css-loader sostyles
looks something like this:If I don't include modules option in css-loader, JSON file is correct but
styles
is an empty object.If I omit postcss-modules,
styles
looks as desired but of course, no JSON file is generated, and I need this for server part.Why does postcss-modules change local variable used in css-loader? Why is
styles
an empty object if I don't add modules options to css-loader? How can I combine both together?The text was updated successfully, but these errors were encountered: