-
Notifications
You must be signed in to change notification settings - Fork 7
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
Does it support css files #48
Comments
Hi. CSS files are modules after they processed with |
If you want to modify CSS files after {
plugins: [
new ModifyModuleSourcePlugin({
test: /\.css$/
})
],
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
}
]
}
} In this case one the same CSS file will be modified twice, because Webpack will create two normal modules:
And this problem is not only with CSS files. It's how works with all files if they processed with multiple loaders. So, I think we need to find way to modify raw files before they multiply as modules. And then we should rename our plugin to |
@matthewma7 You can share more about your use case, so I can try help you |
Hi @artemirq , Thank you for the detailed answer! My use case is relatively simple. I have a css file within a node_module package that has a font defined with url('http://foo.com/font.woff2)', instead of loading the font over the internet, I would like to pack it locally as static media. So I am thinking performing two tasks with a webpack plugin. 1, download the font.woff2 locally, possibly in the same directly along side with the css file. 2, change the url to url('./font.woff2'). |
During the experiments I figured out and fixed all above described problems. Changes is prepared in this PR. Now I understand that I was wrong with raw modules. Yes, we can modify raw CSS files/modules before they got processed by other loaders :) I published all changes under I wrote test with css file and external css file, looks like it's working well. Also added some other changes: renamed class to @matthewma7 So now you can do something like this {
plugins: [
new ModifySourcePlugin({
rules: [
{
test: /node_modules\/modern-normalize\/modern-normalize\.css$/, // external css
modify: (src, file) =>
src + `.myExtraClass { background: gray; /* ${file} */ }`
}
]
})
],
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
}
]
}
} |
Thank you! for the immediate help. 😃 |
@matthewma7 I'm happy that it's works for you. |
Got it. |
@matthewma7 Thank you for the kind words! 😊 ❤️ |
@matthewma7 Hey, I'm started investigating into the issue with two messages and it's looks like it's problem with Did you update |
The reason is that html-webpack-plugin is using a new |
Hi,
Thank you for the plugins, it looks very promising for my use case!
It looks like this plugin prepends a loader to do the modification.
In that case, I am wonder does the plugin work for a .css file (I think css files are also NormalModule)?
The text was updated successfully, but these errors were encountered: