Skip to content

Instantly share code, notes, and snippets.

@SamHoque
Created March 6, 2022 04:11
Show Gist options
  • Save SamHoque/312def4c710a76fa6cd88958270b4531 to your computer and use it in GitHub Desktop.
Save SamHoque/312def4c710a76fa6cd88958270b4531 to your computer and use it in GitHub Desktop.
Nuxt CSS Remapper / Obfuscator
/**
* Nuxt CSS Remapper
* @author SamHoque
*/
const rules = config.module.rules;
const cssLoader = rules.find(rule => rule.test.toString() === '/\\.css$/i');
/**
* Remap oneOf array
*/
cssLoader.oneOf = cssLoader.oneOf.map(loader => {
/**
* Map the `use` array
*/
loader.use = loader.use.map(item => {
const modules = item.options.modules;
if (modules) {
const isProduction = !isDev && isClient;
/**
* Change array value depending on env
* @type {string}
*/
const key = isProduction ? 'getLocalIdent' : 'localIdentName';
modules[key] = isProduction ? getLocalIdent : '[local]';
}
return item;
});
return loader;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment