Skip to content

Instantly share code, notes, and snippets.

@jaysoo
Last active September 5, 2019 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaysoo/431828f47e5202d3e4afc6c34fdac2c0 to your computer and use it in GitHub Desktop.
Save jaysoo/431828f47e5202d3e4afc6c34fdac2c0 to your computer and use it in GitHub Desktop.
const getConfig = require('@nrwl/react/plugins/babel');
const cssModuleRegex = /\.module\.css$/;
module.exports = (config) => {
config = getConfig(config);
config.module.rules.forEach((rule, idx) => {
// Find rule tests for CSS.
// Then make sure it excludes .module.css files.
if (rule.test.test('foo.css')) {
rule.exclude = rule.exclude
? Array.isArray(rule.exclude)
? [...rule.exclude, cssModuleRegex]
: [rule.exclude, cssModuleRegex]
: cssModuleRegex
}
});
// Add new rule to handle .module.css files by using css-loader
// with modules on.
config.module.rules.push({
test: /\.module\.css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-modules-typescript-loader' },
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1
}
}
]
});
return config;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment