New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

svelte-remove-attributes-preprocessor

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-remove-attributes-preprocessor

Svelte / SvelteKit preprocessor to remove specified attributes (e.g., data-testid, data-cy) at build time. Supports spread syntax and can be enabled via environment variables.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
3
200%
Maintainers
1
Weekly downloads
 
Created
Source

svelte-remove-attributes-preprocessor

Svelte / SvelteKit preprocessor to remove specified attributes (e.g., data-testid, data-cy) at build time. Supports spread syntax and can be enabled via environment variables.

Features

  • 🗑️ Remove attributes at build time (e.g., data-testid)
  • 🔄 Supports spread syntax ({...props})
  • 🌍 Environment variable-based toggling

Installation

pnpm add -D svelte-remove-attributes-preprocessor

Usage

Basic Usage

Add the preprocessor to your svelte.config.js:

import { removeAttributesPreprocessor } from 'svelte-remove-attributes-preprocessor';

export default {
	preprocess: [
		removeAttributesPreprocessor({
			attributes: ['data-testid']
		})
	]
};

With Environment Variable

Enable/disable attribute removal via environment variable:

import { removeAttributesPreprocessor } from 'svelte-remove-attributes-preprocessor';

export default {
	preprocess: [
		removeAttributesPreprocessor({
			envVar: 'STRIP_ATTRIBUTES', // default: 'STRIP_ATTRIBUTES'
			expected: '1', // default: '1'
			attributes: ['data-testid']
		})
	]
};

Then set the environment variable when building:

STRIP_ATTRIBUTES=1 pnpm build

SvelteKit

For SvelteKit, add it to vite.config.js or svelte.config.js:

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { removeAttributesPreprocessor } from 'svelte-remove-attributes-preprocessor';

export default defineConfig({
	plugins: [sveltekit()],
	// ... other config
});

// In svelte.config.js
import adapter from '@sveltejs/adapter-auto';
import { removeAttributesPreprocessor } from 'svelte-remove-attributes-preprocessor';

export default {
	kit: {
		adapter: adapter()
	},
	preprocess: [
		removeAttributesPreprocessor({
			attributes: ['data-testid']
		})
	]
};

Options

OptionTypeDefaultDescription
attributesstring[][]Array of attribute names to remove
envVarstring'STRIP_ATTRIBUTES'Environment variable name to check
expectedstring'1'Expected value for the environment variable

Examples

Remove test attributes in production

// svelte.config.js
import { removeAttributesPreprocessor } from 'svelte-remove-attributes-preprocessor';

export default {
	preprocess: [
		removeAttributesPreprocessor({
			attributes: ['data-testid', 'data-cy', 'data-test']
		})
	]
};

Conditional removal via environment

// Only remove attributes when STRIP_ATTRIBUTES=1
removeAttributesPreprocessor({
	envVar: 'STRIP_ATTRIBUTES',
	expected: '1',
	attributes: ['data-testid']
})

Keywords

svelte

FAQs

Package last updated on 04 Dec 2025

Related posts