Skip to content

How to import external CSS without changing class names #503

Description

@gpalsingh

When I try to import CSS from node_modules the loader renames all the class names

I found one workaround here
This is what I'm using:

const loadCSS = isServerConfig => ({
	module: {
		rules: [
			{
				test: /\.css$/,
				oneOf: [{
					resourceQuery: /^\?raw$/,
					use: [
						...(isServerConfig ? [] : [ExtractCSSChunks.loader]),
						{
							loader: require.resolve('css-loader'),
							options: {
								onlyLocals: isServerConfig,
							},
						},
					]
				}, {
					use: [
						...(isServerConfig ? [] : [ExtractCSSChunks.loader]),
						{
							loader: require.resolve('css-loader'),
							options: {
								modules: {
									localIdentName: '[name]__[local]--[hash:base64:5]',
								},
								onlyLocals: isServerConfig,
							},
						},
					],
				}]
			},
		],
	},
});

Is there a better way to do it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions