npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-remove-attr

v0.0.6

Published

A Vite plugin designed specifically for React.js projects that allows the removal of specified attributes in production builds. Useful for excluding attributes like 'data-testid' used in testing. Options include specific file extensions, attributes, ignor

Downloads

5,327

Readme

Vite Plugin - React.js Remove Attributes

Simplify your production code and enhance performance with this unique Vite plugin designed specifically for React.js projects. The plugin seamlessly removes specified attributes from your tsx/jsx HTML codes during production builds, ensuring a clutter-free and optimized application.

Through its robust functionality, this Vite plugin elevates your production code to a new level of cleanliness and efficiency. It's a must-have tool for any developer seeking to streamline their React.js applications for production.

version vite version

Table of Contents

Highlighted Features

  1. Selective Attribute Removal: The plugin gives you the power to choose which attributes you want to remove in the production build of your React.js project. This feature is particularly useful for eliminating attributes like ' data-testid', which are only necessary during testing.

  2. File Extension Specificity: Customize the plugin according to the specific needs of your project. You can define which file extensions should be considered for attribute removal. Currently, the plugin supports tsx and jsx extensions.

  3. Granular Exclusions: Have some folders or files you want to exclude from the plugin's operation? No problem. This plugin allows for configurable exemptions, meaning you can specify certain files or folders to be ignored during the attribute removal process.

  4. Clean Production Code: By strategically removing unnecessary attributes, this plugin ensures your production code is cleaner, leaner, and better performing. Say goodbye to bloated code and hello to optimized application performance.

Installation

You can install this plugin through npm:

npm install --save-dev react-remove-attr

Usage

Prerequisites

To use this plugin, you need to have a Vite project set up. Import and use the plugin in your vite.config.js or vite.config.ts file.

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import removeAttr from "react-remove-attr"

export default defineConfig({
    plugins: [
        removeAttr({
            extensions: [],
            attributes: []
        }),
        react(),
    ],
})

Examples

Example 1: Removing 'data-testid', 'data-timestamp' and 'ignored-element' attributes from '.tsx' and ".jsx" files

This configuration will remove 'data-testid', 'data-timestamp' and 'ignored-element' attributes from all '.tsx' and ".jsx" files in the production build.

export default defineConfig({
    plugins: [
        removeAttr({
            extensions: [ "jsx", "tsx" ],
            attributes: [ 'data-testid', "data-timestamp", "ignored-element" ]
        }),
        react()
    ]
})

Example 2: Ignoring specific folders and files

This configuration will remove 'data-testid' attributes from '.tsx' files, with the exception of those in the 'src/tests' and 'src/utilities' folders, as well as the 'src/Home.tsx', ' src/components/Modal.tsx', and 'src/layouts/LayoutAuth.tsx' files.

export default defineConfig({
    plugins: [
        removeAttr({
            extensions: [ "tsx" ],
            attributes: [ 'data-testid'],
            ignoreFolders: [ 'src/tests', "src/utilities" ],
            ignoreFiles: [ 'src/Home.tsx', 'src/components/Modal.tsx', "src/layouts/LayoutAuth.tsx" ]
        }),
        react()
    ]
})

License

License