Skip to content

Instantly share code, notes, and snippets.

@jaydenlin
Created November 1, 2018 01:46
Show Gist options
  • Save jaydenlin/7bcdaa2707a2aa29f61dd9ec2868284f to your computer and use it in GitHub Desktop.
Save jaydenlin/7bcdaa2707a2aa29f61dd9ec2868284f to your computer and use it in GitHub Desktop.
next.config.js
const withCSS = require('@zeit/next-css')
const path = require('path')
// module.exports = withCSS({
// cssModules: true
// })
const avoidPaths = ['node_modules/@shopify/polaris/', 'node_modules/rc-steps/assets/', 'node_modules/react-table/', 'node_modules/react-toastify/dist/', 'node_modules/react-id-swiper/src/styles/css/swiper.css'].map(d => path.join(__dirname, d));
function canBeTransformed(pathToCheck) {
return !avoidPaths.some(function(v) {
const path = pathToCheck.substr(0, pathToCheck.lastIndexOf('/') + 1);
return v.includes(path);
});
}
// prettier-ignore
module.exports = withCSS({
cssModules: true,
cssLoaderOptions: {
getLocalIdent: (loaderContext, localIdentName, localName, options) => {
const fileName = path.basename(loaderContext.resourcePath)
const shoudTransform = canBeTransformed(loaderContext.resourcePath)
if(!shoudTransform){
console.log(localName);
return localName
}else{
const name = fileName.replace(/\.[^/.]+$/, "")
const suffix = name.substring(name.lastIndexOf("_") + 1);
return `${name}___${localName}`
}
}
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment