vite-plugin-strip-comments 0.0.1 → 0.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.
- package/README.md +5 -4
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -7
- package/dist/index.mjs +33 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -6
- package/tsconfig.json +1 -1
package/README.md
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/vite-plugin-strip-comments)
|
|
6
6
|
[](http://npm-stat.com/charts.html?package=vite-plugin-strip-comments)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
|
-
[](https://vitest.dev/)
|
|
9
|
+
[](https://github.com/vitejs)
|
|
10
10
|
|
|
11
|
-
A simple Vite plugin for stripping comments in your production code. Some comments just don't get removed no matter what minify options you set, especially `/* istanbul ignore */` flags.
|
|
11
|
+
A very simple Vite plugin for stripping comments in your production code. Some comments just don't get removed no matter what minify options you set, especially `/* istanbul ignore */` flags. Keep in mind this is experimental, please **use with caution**.
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
@@ -25,7 +25,7 @@ npm install -D vite-plugin-strip-comments
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
deno
|
|
28
|
+
deno add -D npm:vite-plugin-strip-comments@latest
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
## Usage
|
|
@@ -48,6 +48,7 @@ export default defineConfig({
|
|
|
48
48
|
* **none** removes all comments
|
|
49
49
|
* **keep-legal** remove all commments except those which contain `@legal` or `@license`, a very good practice to allow open source to shine yes?
|
|
50
50
|
* **istanbul** (default) only remove comments that target istanbul code coverage instrumentation (EG: `/* istanbul ignore else @preserve */`)
|
|
51
|
+
* enforce: "pre" (default) | "post" - determines where in the compilation pipeline the plugin should work;
|
|
51
52
|
|
|
52
53
|
## Contributions
|
|
53
54
|
* Found a problem, [report](https://github.com/thednp/vite-plugin-strip-comments/issues) the problem. Thank you!
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const l={none
|
|
1
|
+
"use strict";const c={type:"istanbul",enforce:"pre"},p=(l={})=>{const s={type:["none","keep-legal","istanbul"].some(e=>e===l.type)?l.type:c.type,enforce:["pre","post"].some(e=>e===l.enforce)?l.enforce:c.enforce};return{name:"vite-plugin-strip-comments",enforce:s.enforce,transform(e,o){if(!o||o.includes("node_modules"))return e;let t=e,n;const a=Array.from(e.matchAll(/\/\*[\s\S]*?\*\/|\/\/.*/gm));for(let r=0;r<a.length;r+=1)switch([n]=a[r],s.type){case"keep-legal":["@legal","@license"].some(i=>n.includes(i))||(t=t.replaceAll(n,""));break;case"istanbul":n.includes("istanbul")&&(t=t.replaceAll(n,""));break;case"none":default:t=t.replaceAll(n,"")}return t}}};module.exports=p;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { type Plugin } from \"vite\";\n\nexport type StripCommentsPlugin = Plugin & {\n name: string;\n enforce: \"pre\" | \"post\" | undefined;\n transform: (\n code: string,\n id?: string,\n ) => string;\n};\n\nexport type StripCommentsConfig = {\n type: \"none\" | \"keep-legal\" | \"istanbul\";\n enforce: \"pre\" | \"post\" | undefined;\n};\n\nconst StripCommentsDefaultConfig: StripCommentsConfig = {\n type: \"istanbul\",\n enforce: \"pre\",\n};\n\nconst stripComments = (cfg: Partial<StripCommentsConfig> = {}) => {\n const config: Partial<StripCommentsConfig> = {\n type:\n ([\"none\", \"keep-legal\", \"istanbul\"].some((x) => x === cfg.type)\n ? cfg.type\n : StripCommentsDefaultConfig.type) as StripCommentsConfig[\"type\"],\n enforce:\n ([\"pre\", \"post\"].some((x) => x === cfg.enforce)\n ? cfg.enforce\n : StripCommentsDefaultConfig.enforce) as StripCommentsConfig[\"enforce\"],\n };\n\n return {\n name: \"vite-plugin-strip-comments\",\n enforce: config.enforce,\n transform(code: string, id?: string) {\n /* istanbul ignore if @preserve */\n if (!id || id.includes(\"node_modules\")) return code;\n let result = code;\n let match: string;\n\n const matchesArray = Array.from(code.matchAll(\n /\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*/gm,\n ));\n\n for (let i = 0; i < matchesArray.length; i += 1) {\n // capture first match\n [match] = matchesArray[i];\n\n switch (config.type) {\n case \"keep-legal\":\n if (![\"@legal\", \"@license\"].some((x) => match.includes(x))) {\n result = result.replaceAll(match, \"\");\n }\n break;\n case \"istanbul\":\n if (match.includes(\"istanbul\")) {\n /* istanbul ignore next @preserve */\n result = result.replaceAll(match, \"\");\n }\n break;\n case \"none\":\n default:\n result = result.replaceAll(match, \"\");\n }\n }\n\n return result;\n },\n } satisfies StripCommentsPlugin;\n};\n\nexport default stripComments;\n"],"names":["StripCommentsDefaultConfig","stripComments","cfg","config","x","code","id","result","match","matchesArray","i"],"mappings":"aAgBA,MAAMA,EAAkD,CACtD,KAAM,WACN,QAAS,KACX,EAEMC,EAAgB,CAACC,EAAoC,KAAO,CAChE,MAAMC,EAAuC,CAC3C,KACG,CAAC,OAAQ,aAAc,UAAU,EAAE,KAAMC,GAAMA,IAAMF,EAAI,IAAI,EAC1DA,EAAI,KACJF,EAA2B,KACjC,QACG,CAAC,MAAO,MAAM,EAAE,KAAMI,GAAMA,IAAMF,EAAI,OAAO,EAC1CA,EAAI,QACJF,EAA2B,OACnC,EAEO,MAAA,CACL,KAAM,6BACN,QAASG,EAAO,QAChB,UAAUE,EAAcC,EAAa,CAEnC,GAAI,CAACA,GAAMA,EAAG,SAAS,cAAc,EAAU,OAAAD,EAC/C,IAAIE,EAASF,EACTG,EAEE,MAAAC,EAAe,MAAM,KAAKJ,EAAK,SACnC,2BAAA,CACD,EAED,QAASK,EAAI,EAAGA,EAAID,EAAa,OAAQC,GAAK,EAI5C,OAFC,CAAAF,CAAK,EAAIC,EAAaC,CAAC,EAEhBP,EAAO,KAAM,CACnB,IAAK,aACE,CAAC,SAAU,UAAU,EAAE,KAAMC,GAAMI,EAAM,SAASJ,CAAC,CAAC,IAC9CG,EAAAA,EAAO,WAAWC,EAAO,EAAE,GAEtC,MACF,IAAK,WACCA,EAAM,SAAS,UAAU,IAElBD,EAAAA,EAAO,WAAWC,EAAO,EAAE,GAEtC,MACF,IAAK,OACL,QACWD,EAAAA,EAAO,WAAWC,EAAO,EAAE,CAAA,CAInC,OAAAD,CAAA,CAEX,CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
declare const stripComments: (cfg?: Partial<StripCommentsConfig>) => {
|
|
2
2
|
name: string;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
map: null;
|
|
6
|
-
} | undefined;
|
|
3
|
+
enforce: "pre" | "post" | undefined;
|
|
4
|
+
transform(code: string, id?: string): string;
|
|
7
5
|
};
|
|
8
6
|
export default stripComments;
|
|
9
7
|
|
|
10
|
-
/**
|
|
11
|
-
* @default 'istanbul'
|
|
12
|
-
*/
|
|
13
8
|
declare type StripCommentsConfig = {
|
|
14
9
|
type: "none" | "keep-legal" | "istanbul";
|
|
10
|
+
enforce: "pre" | "post" | undefined;
|
|
15
11
|
};
|
|
16
12
|
|
|
17
13
|
export { }
|
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
const c = {
|
|
2
|
+
type: "istanbul",
|
|
3
|
+
enforce: "pre"
|
|
4
|
+
}, p = (l = {}) => {
|
|
5
|
+
const s = {
|
|
6
|
+
type: ["none", "keep-legal", "istanbul"].some((e) => e === l.type) ? l.type : c.type,
|
|
7
|
+
enforce: ["pre", "post"].some((e) => e === l.enforce) ? l.enforce : c.enforce
|
|
8
|
+
};
|
|
9
|
+
return {
|
|
10
|
+
name: "vite-plugin-strip-comments",
|
|
11
|
+
enforce: s.enforce,
|
|
12
|
+
transform(e, a) {
|
|
13
|
+
if (!a || a.includes("node_modules")) return e;
|
|
14
|
+
let t = e, n;
|
|
15
|
+
const o = Array.from(e.matchAll(
|
|
16
|
+
/\/\*[\s\S]*?\*\/|\/\/.*/gm
|
|
17
|
+
));
|
|
18
|
+
for (let r = 0; r < o.length; r += 1)
|
|
19
|
+
switch ([n] = o[r], s.type) {
|
|
20
|
+
case "keep-legal":
|
|
21
|
+
["@legal", "@license"].some((i) => n.includes(i)) || (t = t.replaceAll(n, ""));
|
|
22
|
+
break;
|
|
23
|
+
case "istanbul":
|
|
24
|
+
n.includes("istanbul") && (t = t.replaceAll(n, ""));
|
|
25
|
+
break;
|
|
26
|
+
case "none":
|
|
27
|
+
default:
|
|
28
|
+
t = t.replaceAll(n, "");
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
17
31
|
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
20
34
|
export {
|
|
21
|
-
|
|
35
|
+
p as default
|
|
22
36
|
};
|
|
23
37
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { type Plugin } from \"vite\";\n\nexport type StripCommentsPlugin = Plugin & {\n name: string;\n enforce: \"pre\" | \"post\" | undefined;\n transform: (\n code: string,\n id?: string,\n ) => string;\n};\n\nexport type StripCommentsConfig = {\n type: \"none\" | \"keep-legal\" | \"istanbul\";\n enforce: \"pre\" | \"post\" | undefined;\n};\n\nconst StripCommentsDefaultConfig: StripCommentsConfig = {\n type: \"istanbul\",\n enforce: \"pre\",\n};\n\nconst stripComments = (cfg: Partial<StripCommentsConfig> = {}) => {\n const config: Partial<StripCommentsConfig> = {\n type:\n ([\"none\", \"keep-legal\", \"istanbul\"].some((x) => x === cfg.type)\n ? cfg.type\n : StripCommentsDefaultConfig.type) as StripCommentsConfig[\"type\"],\n enforce:\n ([\"pre\", \"post\"].some((x) => x === cfg.enforce)\n ? cfg.enforce\n : StripCommentsDefaultConfig.enforce) as StripCommentsConfig[\"enforce\"],\n };\n\n return {\n name: \"vite-plugin-strip-comments\",\n enforce: config.enforce,\n transform(code: string, id?: string) {\n /* istanbul ignore if @preserve */\n if (!id || id.includes(\"node_modules\")) return code;\n let result = code;\n let match: string;\n\n const matchesArray = Array.from(code.matchAll(\n /\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*/gm,\n ));\n\n for (let i = 0; i < matchesArray.length; i += 1) {\n // capture first match\n [match] = matchesArray[i];\n\n switch (config.type) {\n case \"keep-legal\":\n if (![\"@legal\", \"@license\"].some((x) => match.includes(x))) {\n result = result.replaceAll(match, \"\");\n }\n break;\n case \"istanbul\":\n if (match.includes(\"istanbul\")) {\n /* istanbul ignore next @preserve */\n result = result.replaceAll(match, \"\");\n }\n break;\n case \"none\":\n default:\n result = result.replaceAll(match, \"\");\n }\n }\n\n return result;\n },\n } satisfies StripCommentsPlugin;\n};\n\nexport default stripComments;\n"],"names":["StripCommentsDefaultConfig","stripComments","cfg","config","x","code","id","result","match","matchesArray","i"],"mappings":"AAgBA,MAAMA,IAAkD;AAAA,EACtD,MAAM;AAAA,EACN,SAAS;AACX,GAEMC,IAAgB,CAACC,IAAoC,OAAO;AAChE,QAAMC,IAAuC;AAAA,IAC3C,MACG,CAAC,QAAQ,cAAc,UAAU,EAAE,KAAK,CAACC,MAAMA,MAAMF,EAAI,IAAI,IAC1DA,EAAI,OACJF,EAA2B;AAAA,IACjC,SACG,CAAC,OAAO,MAAM,EAAE,KAAK,CAACI,MAAMA,MAAMF,EAAI,OAAO,IAC1CA,EAAI,UACJF,EAA2B;AAAA,EACnC;AAEO,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAASG,EAAO;AAAA,IAChB,UAAUE,GAAcC,GAAa;AAEnC,UAAI,CAACA,KAAMA,EAAG,SAAS,cAAc,EAAU,QAAAD;AAC/C,UAAIE,IAASF,GACTG;AAEE,YAAAC,IAAe,MAAM,KAAKJ,EAAK;AAAA,QACnC;AAAA,MAAA,CACD;AAED,eAASK,IAAI,GAAGA,IAAID,EAAa,QAAQC,KAAK;AAI5C,gBAFC,CAAAF,CAAK,IAAIC,EAAaC,CAAC,GAEhBP,EAAO,MAAM;AAAA,UACnB,KAAK;AACH,YAAK,CAAC,UAAU,UAAU,EAAE,KAAK,CAACC,MAAMI,EAAM,SAASJ,CAAC,CAAC,MAC9CG,IAAAA,EAAO,WAAWC,GAAO,EAAE;AAEtC;AAAA,UACF,KAAK;AACC,YAAAA,EAAM,SAAS,UAAU,MAElBD,IAAAA,EAAO,WAAWC,GAAO,EAAE;AAEtC;AAAA,UACF,KAAK;AAAA,UACL;AACW,YAAAD,IAAAA,EAAO,WAAWC,GAAO,EAAE;AAAA,QAAA;AAInC,aAAAD;AAAA,IAAA;AAAA,EAEX;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-strip-comments",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "🗃️ Vite plugin for stripping comments in production builds",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -28,13 +28,12 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/thednp/vite-plugin-strip-comments#readme",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/node": "^20.17.
|
|
32
|
-
"@vitest/coverage-istanbul": "^2.1.
|
|
33
|
-
"playwright": "^1.48.2",
|
|
31
|
+
"@types/node": "^20.17.6",
|
|
32
|
+
"@vitest/coverage-istanbul": "^2.1.5",
|
|
34
33
|
"typescript": "^5.6.3",
|
|
35
|
-
"vite": "^5.4.
|
|
34
|
+
"vite": "^5.4.11",
|
|
36
35
|
"vite-plugin-dts": "^4.3.0",
|
|
37
|
-
"vitest": "^2.1.
|
|
36
|
+
"vitest": "^2.1.5"
|
|
38
37
|
},
|
|
39
38
|
"engines": {
|
|
40
39
|
"node": ">=20",
|