Skip to content

Instantly share code, notes, and snippets.

@LinusBorg
Last active Mar 9, 2020
Embed
What would you like to do?
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