Skip to content
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
This repository was archived by the owner on Aug 27, 2026. It is now read-only.

Add ID's to <style> tags #216

Description

@alex-mm

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

require('style-loader?{attrs:{id: "style-tag-id"}}!style.css');

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'.

	var findPackage = require('find-package');
        ...
	if(this.cacheable) this.cacheable();
	var query = loaderUtils.getOptions(this) || {};
	var pkg = findPackage(this.resourcePath) || {};
	if (query.attrs) {
		Object.keys(query.attrs).forEach(function(key) {
			query.attrs[key] = query.attrs[key].replace(/\[name\]/ig, pkg.name).replace(/\[version\]/ig, pkg.version);
		});
	}
        return ...

Then

I use it like this

require('style-loader?{attrs:{component: "[name]@[version]"}}!style.css');

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions