Socket
Book a DemoInstallSign in
Socket

@castlenine/vite-remove-attribute

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@castlenine/vite-remove-attribute

A Vite plugin that enables the removal of specified attributes, which is useful for excluding attributes like 'data-testid' that are used in testing. The options include the ability to specify file extensions, attributes, and folders and files to ignore.

Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

@castlenine/vite-remove-attribute

npm.badge download.badge

Vite plugin that allows the removal of specified attributes and supports a variety of options, including file extensions, attributes, ignored folders, and files.

Table of Contents

Features

  • Removes specified attributes
  • Allows you to specify the file extensions to be processed
  • Can ignore certain folders or files based on configuration
  • Ensures clean production code by removing unnecessary attributes, like 'data-testid' used in testing

Installation

Use your package manager to install:

npm i --save-dev @castlenine/vite-remove-attribute

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.

Examples

Example 1: Removing 'data-testid' attributes from .svelte files

This configuration will remove data-testid attributes from all .svelte files in the production build.

import { defineConfig } from 'vite';
import { sveltekit } from '@sveltejs/kit/vite';

import removeAttribute from '@castlenine/vite-remove-attribute';

const IS_PRODUCTION = process.env.NODE_ENV == 'production';

export default defineConfig({
    plugins: [
        sveltekit(),

        IS_PRODUCTION
            ? removeAttribute({
                    extensions: ['svelte'],
                    attributes: ['data-testid'],
                })
            : null,
    ],
});

Example 2: Ignoring specific folders and files

This configuration will remove data-testid and data-id attributes from all .svelte, .ts, and .js files, with the exception of those located in the src/tests and src/utilities folders, as well as the Header.svelte, src/components/Modal.svelte, and src/layouts/LayoutAuth.svelte files in all builds.

import { defineConfig } from 'vite';
import { sveltekit } from '@sveltejs/kit/vite';

import removeAttribute from '@castlenine/vite-remove-attribute';

export default defineConfig({
    plugins: [
        sveltekit(),
        removeAttribute({
            extensions: ['svelte', 'ts', 'js'],
            attributes: ['data-testid', 'data-id'],
            ignoreFolders: ['src/tests', 'src/utilities'],
            ignoreFiles: ['Header.svelte', 'src/components/Modal.svelte', 'src/layouts/LayoutAuth.svelte'],
        }),
    ],
});

Forked from mustafadalga/remove-attr

Keywords

attribute

FAQs

Package last updated on 09 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts