Skip to content

Instantly share code, notes, and snippets.

@ScriptedAlchemy
Created February 3, 2021 20:31
Show Gist options
  • Save ScriptedAlchemy/5a3fca1ef9f045060188a7737eab2221 to your computer and use it in GitHub Desktop.
Save ScriptedAlchemy/5a3fca1ef9f045060188a7737eab2221 to your computer and use it in GitHub Desktop.
Next.js pure css enforcement override
const withLocalCSS = (nextConfig = {}) => Object.assign({}, nextConfig, {
webpack: (config, options) => {
const nextCssLoaders = config.module.rules.find(rule => typeof rule.oneOf === 'object');
// .module.css
if (nextCssLoaders) {
nextCssLoaders.oneOf.forEach(
(rule) => {
if (rule.use) {
if (Array.isArray(rule.use)) {
const badLoader = rule.use.find(loader => loader.loader.includes('css-loader') && loader.options.modules);
if(badLoader) {
badLoader.options.modules = 'local';
}
}
}
},
);
}
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options);
}
return config;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment