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
modules.auto=true ignores module.css!=!./some-file #1381
Comments
You can do - |
hm, also we already support it https://github.com/webpack-contrib/css-loader/blob/master/src/utils.js#L523, check your css-loader version |
In future we will drop it, because it is wrong, I recommend to use #1381 (comment) |
Hey Alex :) thanks for your quick response! Unfortunately it is not working with css-loader 6.3.0 (latest). Here is a full (but minimal) reproduction example which is not working: If you remove I also checked https://github.com/webpack-contrib/css-loader/blob/master/src/utils.js#L523 and |
I can't open your archive, can you use github and create repo?
No |
Oh sorry.. sure here is the repo https://github.com/jantimon/css-loader-issue-1381 I also checked in the dist file so you can see that there are no class names exported: to see the expected result deleting the following line: |
@alexander-akait could you please reopen the issue? |
I will look at this in near future and describe why it will not work |
import { demo } from './styles.module.css!=!./colors.modules.txt' again |
hey alex thank you so much for your patience and time :) I am asking those questions to improve an open source plugin (linaria) with webpacks new importModule loader api.. so I won't make any money out of it but still I would like to send you a small present from switzerland.. if you like sweets let me know your address (send me an email) and I'll send sth small Linaria is a plugin which already works well with existing webpack configs like nextjs so I would rather prefer not to introduce a query with custom extract css and css-loader configuration on top I'll need to take a closer look and will create a bug for the extract css plugin loader if it makes sense.. in the end it would be cool if it works the same way for style-loader and extract css plugin - what do you think? thanks already for pointing me to the right direction :) |
@jantimon Why do you use this syntax? Can you provide more context? Why it is JS file? Do you extract CSS from JS file? |
exactly - in short (very basic example): const Button = styled.div`
color: red
` is converted twice with two outputs:
however there is more - it maps runtime code to css-variables and has improved tree shaking for js code which runs only at build time if you like to see it in action I can prepare a codesandbox for you |
So you want to extract CSS from JS file and when bundle it using
and you don't want to rename JS file on |
that's correct :) I would like to do the following transform (simplified): file1.js export const Button = styled.button`color:orange`; to: import { buttonClass } from './file1.module.css!=!./file1.js'
export const Button = (content) => `<button class="${buttonClass}">${content}</button>` |
in the meantime I found a hack to not use file1.js export const Button = styled.button`color:orange`; to: import { buttonClass } from 'my-lib/placeholder.module.css?extractFrom=/absolute/path/to/file1.js'
export const Button = (content) => `<button class="${buttonClass}">${content}</button>` that way I can reuse all existing |
@jantimon let's open an issue in webpack, because I can't control it in |
Bug report
The css-loader option
module: { auto: true }
provides a great default for mixing css files and css modules.Many webpack abstractions like cra or nextjs make use of it.
Lets say we have the following css-loader configuration:
It works if the real file is called
./demo.module.css
However if there is only a synthetic css file e.g. if a
.js
file contains the css it works only partially.Webpack uses the correct loader however the
css-loader
does not identify the file as a.module.css
file:Actual Behavior
The css-loader acts the very same way as if css modules would be disabled
Expected Behavior
The css-loader should identify synthetic file names in
auto
modeHow Do We Reproduce?
index.js
file.js
Please paste the results of
npx webpack-cli info
here, and mention other relevant informationIf you think this should be fixed I can work on a PR if you like
The text was updated successfully, but these errors were encountered: