-
-
Notifications
You must be signed in to change notification settings - Fork 470
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
Add ID's to <style> tags #216
Comments
@alex-mm What's the particular usecase for this in terms of development ? 😛 |
It is mainly to help developers identify which components and versions. When the dependent components are many, there are some common dependencies, especially when the dependent version is different, there will be style coverage problems, it is difficult to find which component is wrong version, there will also be repeated insert the situation, you are It is hard to see which component is repeated. By adding the information on the 'attr', you can clearly find out the problem. By making the private package, we've done it, it's really useful. |
I would appreciate it too. It is kind of frustrating to be able to add only "static values" to the attributes of the injected |
We could maybe include the filename as attribute, but I'm still not really convinced by the idea. If this is really wanted someone feel free/please open a PR for further discussion |
It might help you to remove stylesheet by id in unuse()/unref() |
Really need this feature, like |
I'm using this: options: {
attrs: { title: 'less' }
} It renders, however for some strange reason the style is not applied to the page... |
+1 would like this to help debug styling issues |
@pixeldrew PR welcome 👍 |
Don't use:
But maybe:
? |
What if the
|
PR welcome |
Simple temporary solution without modily the lib(version 0.23.1):
const path = require('path')
const loader = require('style-loader')
module.exports = function () {
}
module.exports.pitch = function (request) {
const result = loader.pitch.call(this, request)
const index = result.indexOf('options.transform = transform\n')
if (index <= -1) return result
const insertIndex = index - 1
// eslint-disable-next-line prefer-destructuring
const resourcePath = this.resourcePath
const relativePath = path.relative(path.resolve(__dirname, '..'), resourcePath)
const insertAttr = `
if (typeof options.attrs !== 'object') {
options.attrs = {}
}
options.attrs["source-path"] = '${relativePath}' // do anything you want
`
return result.slice(0, insertIndex) + insertAttr + result.slice(insertIndex)
}
{
test: /\.css$/,
use: [
'./build/style-loader',
'css-loader'
]
} The loader output code will be like: var options = {"attrs":{"name":"aa"},"hmr":true}
if (typeof options.attrs !== 'object') {
options.attrs = {}
}
options.attrs["source-path"] = 'src/components/color-picker.less'
options.transform = transform
options.insertInto = undefined; The element in header: |
any news regards webpack placeholders? I'm tryinig to insert the file name as a source attribute and [name] is being ignored... |
I could really use this in runtime for caching. I have multiple apps bundling the same ui library (not externalised for a reason), resulting in the insertion of the same CSS and the only seemingly possible way to avoid that, is by calculating a content hash in build-time and then pass it to the style tag with an attribute |
我直接报this.getOptions相关错误 |
Why ?
I have many components. And I can not use 'ExtractTextPlugin' for special reasons.
I would like to distinguish which component and the version number to use.
How ?
I found the
attrs
But the information of the component can only be obtained in the compilation of each file.
So
I would like to make this change in 'style-loader/index.js'.
Then
I use it like this
The result:
If it is acceptable ? Or is there any other solution?
Fork: https://github.com/alex-mm/style-loader/blob/master/index.js#L7-L17
The text was updated successfully, but these errors were encountered: