Skip to content

Instantly share code, notes, and snippets.

@mostafa7904
Last active May 10, 2022 14:59
Show Gist options
  • Save mostafa7904/f20f03a863be59396d9a7e623caeaf58 to your computer and use it in GitHub Desktop.
Save mostafa7904/f20f03a863be59396d9a7e623caeaf58 to your computer and use it in GitHub Desktop.
Remove test attributes from your production code in nuxt
// 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