@castlenine/vite-remove-attribute 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +55 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -9,12 +9,18 @@ Vite plugin that allows the removal of specified attributes and supports a varie
9
9
 
10
10
  ## Table of Contents
11
11
 
12
+ - [Disclaimer](#disclaimer)
12
13
  - [Features](#features)
13
14
  - [Installation](#installation)
14
15
  - [Usage](#usage)
15
16
  - [Prerequisites](#prerequisites)
17
+ - [Notes](#notes)
16
18
  - [Examples](#examples)
17
19
 
20
+ ## Disclaimer
21
+
22
+ **Only tested with Svelte, SvelteKit and Vue.js projects**. Please open an issue if you encounter any problems with other frameworks.
23
+
18
24
  ## Features
19
25
 
20
26
  - Removes specified attributes
@@ -34,12 +40,15 @@ npm i --save-dev @castlenine/vite-remove-attribute
34
40
 
35
41
  ### Prerequisites
36
42
 
37
- To use this plugin, you need to have a Vite project set up. Import and use the plugin in your `vite.config.js` or
38
- `vite.config.ts` file.
43
+ To use this plugin, you must have a Vite config file set up in your project. If you don't have one, create a `vite.config.js` or `vite.config.ts` file in the root of your project.
44
+
45
+ ### Notes
46
+
47
+ For some frameworks, like Svelte & SvelteKit, this plugin should be placed first (before the framework's plugin) in the `plugins` array and for others, like Vue.js, it should be placed after the framework's plugin.
39
48
 
40
49
  ## Examples
41
50
 
42
- ### Example 1: Removing 'data-testid' attributes from `.svelte` files
51
+ ### SvelteKit example 1: Removing 'data-testid' attributes from `.svelte` files
43
52
 
44
53
  This configuration will remove `data-testid` attributes from all `.svelte` files in the production build.
45
54
 
@@ -53,19 +62,19 @@ const IS_PRODUCTION = process.env.NODE_ENV == 'production';
53
62
 
54
63
  export default defineConfig({
55
64
  plugins: [
56
- sveltekit(),
57
-
58
65
  IS_PRODUCTION
59
66
  ? removeAttribute({
60
67
  extensions: ['svelte'],
61
68
  attributes: ['data-testid'],
62
69
  })
63
70
  : null,
71
+
72
+ sveltekit(), // SvelteKit plugin should be placed after removeAttribute
64
73
  ],
65
74
  });
66
75
  ```
67
76
 
68
- ### Example 2: Ignoring specific folders and files
77
+ ### SvelteKit example 2: Ignoring specific folders and files
69
78
 
70
79
  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.
71
80
 
@@ -77,17 +86,56 @@ import removeAttribute from '@castlenine/vite-remove-attribute';
77
86
 
78
87
  export default defineConfig({
79
88
  plugins: [
80
- sveltekit(),
81
89
  removeAttribute({
82
90
  extensions: ['svelte', 'ts', 'js'],
83
91
  attributes: ['data-testid', 'data-id'],
84
92
  ignoreFolders: ['src/tests', 'src/utilities'],
85
93
  ignoreFiles: ['Header.svelte', 'src/components/Modal.svelte', 'src/layouts/LayoutAuth.svelte'],
86
94
  }),
95
+
96
+ sveltekit(), // SvelteKit plugin should be placed after removeAttribute
87
97
  ],
88
98
  });
89
99
  ```
90
100
 
101
+ ### Vue.js example 1: Removing 'data-testid' attributes from '.vue' files
102
+
103
+ This configuration will remove 'data-testid' attributes from all '.vue' files in the production build.
104
+
105
+ ```typescript
106
+ const IS_PRODUCTION = process.env.NODE_ENV == 'production';
107
+
108
+ export default defineConfig({
109
+ plugins: [
110
+ vue(), // Vue plugin should be placed before removeAttribute
111
+ IS_PRODUCTION
112
+ ? removeAttribute({
113
+ extensions: ['vue'],
114
+ attributes: ['data-testid'],
115
+ })
116
+ : null,
117
+ ]
118
+ })
119
+ ```
120
+
121
+ #### Vue.js example 2: Ignoring specific folders and files
122
+
123
+ This configuration will remove `data-testid` and `data-id` attributes from all `.vue`, `.ts`, and `.js` files, with the exception of those located in the `src/tests` and `src/utilities` folders, as well as the `Header.vue`, `src/components/Modal.vue`, and `src/layouts/LayoutAuth.vue` files in all builds.
124
+
125
+ ```typescript
126
+ export default defineConfig({
127
+ plugins: [
128
+ vue(), // Vue plugin should be placed before removeAttribute
129
+ removeAttr({
130
+ extensions: [ 'vue', "ts", "js" ],
131
+ attributes: [ 'data-testid', "data-id" ],
132
+ ignoreFolders: [ 'src/tests', "src/utilities" ],
133
+ ignoreFiles: [ 'Header.vue', 'src/components/Modal.vue', "src/layouts/LayoutAuth.vue" ]
134
+ })
135
+ ]
136
+ })
137
+ ```
138
+
91
139
  <br />
92
140
 
93
141
  Forked from [mustafadalga/remove-attr](https://github.com/mustafadalga/remove-attr)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@castlenine/vite-remove-attribute",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "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.",
5
5
  "license": "MIT",
6
6
  "keywords": [