react-union icon indicating copy to clipboard operation
react-union copied to clipboard

How to import external CSS without changing class names

Open gpalsingh opened this issue 4 years ago • 0 comments

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?

gpalsingh avatar Sep 15 '20 07:09 gpalsingh