Created
February 3, 2021 20:31
-
-
Save ScriptedAlchemy/5a3fca1ef9f045060188a7737eab2221 to your computer and use it in GitHub Desktop.
Next.js pure css enforcement override
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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