Skip to content

Instantly share code, notes, and snippets.

@LinusBorg
Last active March 9, 2020 19:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LinusBorg/6d9919904ca395b418c8a86648ca656b to your computer and use it in GitHub Desktop.
Save LinusBorg/6d9919904ca395b418c8a86648ca656b to your computer and use it in GitHub Desktop.
Compiler Module for vue-loader to remove data-test attributes
/*
*
* Usage:
* compilerModules: [
* createDataAttributeRemover(['test', 'test-data'])
* ]
*
*/
function createDataAttributeRemover(attributes = []) {
return {
preTransformNode(astEl) {
if (process.env.NODE_ENV === 'production') {
const { attrsMap, attrsList } = astEl
attributes.forEach(attr => {
const dataAttr = `data-${attr}`
if (attrsMap[dataAttr]) {
delete attrsMap[dataAttr]
const index = attrsList.findIndex(x => x.name == dataAttr)
attrsList.splice(index, 1)
}
})
}
return astEl
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment