vue-remove-attributes

A vue-template-compiler module that removes unwanted attributes from templates.
59,800 16
Install
npm install vue-remove-attributes
Latest Version:1.0.3
Vue:2
License:MIT
Last Updated:Jan 4, 2023
Links: GitHub  ·  npm
Maintainer: emensch

vue-remove-attributes

CircleCI NPM

A vue-template-compiler module that removes unwanted attributes from templates. Neat!

Installation & Usage

Install:

npm install -D vue-remove-attributes

Use:

Import and add to your webpack configuration:

ES Module:

import createAttributeRemover from 'vue-remove-attributes';

CommonJS:

const createAttributeRemover = require('vue-remove-attributes');

Pass the module to vue-loader in your webpack config:

module: {
  rules: [{
    test: /\.vue$/,
    use: {
      loader: 'vue-loader',
      options: {
        compilerOptions: {
          modules: [
            createAttributeRemover('data-testid')
          ]
        }
      }
    }
  }]
}

Voilà! Your vue templates, littered with unwanted attributes (for tests, etc):

<template>
  <ul class="list" data-testid="test-list">
    <li
      class="list-item"
      v-for="n in 3"
      data-testid="test-item"
    >
      {{ n }}
    </li>
  </ul>
</template>

Now beautiful for production:

<ul class="list">
  <li class="list-item"> 1 </li>
  <li class="list-item"> 2 </li>
  <li class="list-item"> 3 </li>
</ul>

Saving us entire bytes over the wire. :rocket:

API:

createAttributeRemover(matcher)

Returns a vue-template-compiler module.

  • matcher - Criteria to match attributes against. Can be one of the following types:
    • string - createAttributeRemover('data-testid') will remove data-testid
    • string[] - createAttributeRemover(['data-foo', 'data-bar']) will remove data-foo and data-bar
    • RegExp - createAttributeRemover(/^:?data-testid$/) will remove data-testid and :data-testid

Note: The module will match attributes as their raw values in Vue templates, not their compiled result. As such, data-testid, :data-testid, and v-bind:data-testid are all treated as separate attributes, even though they render identically. Specify each permutation explicitly for a comprehensive removal experience, e.g. createAttributeRemover(['data-testid', ':data-testid', 'v-bind:data-testid']).

License

MIT

Related Packages

vue-template-loader

Vue.js 2.0 template loader for webpack

184,454 263
vue-pug-plugin

Pug to HTML plugin for Vue with proper native pug syntax support

96,839 17
vue-native-template-compiler

Vue Native template compiler, dependency of vue-native-scripts. It can also be u...

7,805 8,278
@verter/nuxt

Nuxt module for Verter Vue compiler

1,011 114
@cockernutx/brace-template

Brace-delimited control flow (@if, @for, @switch, @try) for Vue SFC templates

771 0

Version History

Version Released License
1.0.3 MIT
1.0.2 MIT
1.0.1 MIT