-
-
Notifications
You must be signed in to change notification settings - Fork 604
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
Auto resolving css-modules import and default import #994
Comments
|
Closing due to inactivity. |
Sorry. I made mistake. Fixed in the first message: |
@Yegorich555 can you clarify what you want, hard to udnestand |
According to css-modules specification we have to use: But for switching on css-modules rule we should configure this for exact-files (by regex pattern). Does it makes sense? Why can not it be resolved automatically? I'm not sure is it question for css-loader? Why do I need this:
Here you can see 2 config sections which I use in projects: {
// rules for style-files
test: /\.css$|\.scss$/,
oneOf: [
/* config .oneOf('normal-modules') - rule for [name].module.css files - rule for css-modules */
{
test: /\.module\.\w+$/,
use: [
isDevServer
? "style-loader" // it extracts style directly into html (MiniCssExtractPlugin works incorrect with hmr and modules architecture)
: MiniCssExtractPlugin.loader, // it extracts styles into file *.css
// TODO: improve plugin for splitting by files for dev purpose
{
loader: "css-loader", // it interprets @import and url() like import/require() and it resolves them (you can use [import *.css] into *.js).
options: {
modules: true
}
},
{
loader: "sass-loader", // it compiles Sass to CSS, using Node Sass by default
options: {
data: '@import "variables";', // inject this import by default in each scss-file
includePaths: [path.resolve(__dirname, "src/styles")]
}
},
"postcss-loader" // it provides adding vendor prefixes to CSS rules using values from Can I Use (see postcss.config.js in the project)
]
},
/* config .oneOf('normal') */
{
use: [
isDevServer
? "style-loader" // it extracts style directly into html (MiniCssExtractPlugin works incorrect with hmr and modules architecture)
: MiniCssExtractPlugin.loader, // it extracts styles into file *.css
"css-loader", // it interprets @import and url() like import/require() and it resolves them (you can use [import *.css] into *.js).
{
loader: "sass-loader", // it compiles Sass to CSS, using Node Sass by default
options: {
data: '@import "variables";', // inject this import by default in each scss-file
includePaths: [path.resolve(__dirname, "src/style")]
}
},
"postcss-loader" // it provides adding vendor prefixes to CSS rules using values from Can I Use (see postcss.config.js in the project)
]
}
]
}; |
How can css-config looks like: {
// rules for style-files
test: /\.css$|\.scss$/,
use: [
isDevServer
? "style-loader" // it extracts style directly into html (MiniCssExtractPlugin works incorrect with hmr and modules architecture)
: MiniCssExtractPlugin.loader, // it extracts styles into file *.css
{
loader: "css-loader", // it interprets @import and url() like import/require() and it resolves them (you can use [import *.css] into *.js).
options: {
modules: "auto"
}
},
{
loader: "sass-loader", // it compiles Sass to CSS, using Node Sass by default
options: {
data: '@import "variables";', // inject this import by default in each scss-file
includePaths: [path.resolve(__dirname, "src/styles")]
}
},
"postcss-loader" // it provides adding vendor prefixes to CSS rules using values from Can I Use (see postcss.config.js in the project)
]
}; |
For webpack@5 CSS will be built-in so it is not high priority right now, but idea is good, do you want send a PR (PoC), we have {
// rules for style-files
test: /\.css$|\.scss$/,
use: [
isDevServer
? "style-loader" // it extracts style directly into html (MiniCssExtractPlugin works incorrect with hmr and modules architecture)
: MiniCssExtractPlugin.loader, // it extracts styles into file *.css
{
loader: "css-loader", // it interprets @import and url() like import/require() and it resolves them (you can use [import *.css] into *.js).
options: {
modules: {
test: /\.module\.\w+$/,
}
}
},
{
loader: "sass-loader", // it compiles Sass to CSS, using Node Sass by default
options: {
data: '@import "variables";', // inject this import by default in each scss-file
includePaths: [path.resolve(__dirname, "src/styles")]
}
},
"postcss-loader" // it provides adding vendor prefixes to CSS rules using values from Can I Use (see postcss.config.js in the project)
]
}; |
Yes. Such config looks nice. I like it. What can I do for this? |
Need improve checking here https://github.com/webpack-contrib/css-loader/blob/master/src/index.js#L54 |
very good examplation { |
Feature Proposal
We have two imports ES6 and It looks smarter when resolving some imports will be work in the following automatic way:
import styles from 'someFiles.css'
as css-moduleimport 'someFiles2.css'
as default import (without css-module-specification)Feature Use Case
The main idea is simplifying webpack config and avoiding misunderstanding in mixed project (when we have some files as css-modules and some-files as default-css).
Is implementing of this possible?
The text was updated successfully, but these errors were encountered: