Last active
May 10, 2022 14:59
-
-
Save mostafa7904/f20f03a863be59396d9a7e623caeaf58 to your computer and use it in GitHub Desktop.
Remove test attributes from your production code in nuxt
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
// nuxt.config.js | |
export default { | |
// ... | |
build: { | |
extend(config, ctx) { | |
// All the attributes that we want to be removed from the production bundle | |
let tagAttributesForTesting = ['jest-id'] | |
ctx.loaders.vue.compilerOptions = { | |
modules: [ | |
{ | |
preTransformNode(astEl) { | |
// Make sure we are in production | |
if (!ctx.isDev) { | |
const { attrsMap, attrsList } = astEl | |
tagAttributesForTesting.forEach((attribute) => { | |
if (attrsMap[attribute]) { | |
delete attrsMap[attribute] | |
const index = attrsList.findIndex( | |
(x) => x.name === attribute | |
) | |
attrsList.splice(index, 1) | |
} | |
}) | |
} | |
return astEl | |
}, | |
}, | |
], | |
} | |
}, | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment