vite-plugin-strip-comments 0.0.3 → 0.0.5
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 -5
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +15 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
[](https://github.com/thednp/vite-plugin-strip-comments/actions/workflows/ci.yml)
|
|
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
|
-
[](https://www.typescriptlang.org/)
|
|
8
|
+
[](https://vitest.dev/)
|
|
9
9
|
[](https://github.com/vitejs)
|
|
10
10
|
|
|
11
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**.
|
|
@@ -37,17 +37,17 @@ import stripComments from 'vite-plugin-strip-comments';
|
|
|
37
37
|
export default defineConfig({
|
|
38
38
|
plugins: [
|
|
39
39
|
// ... other plugins
|
|
40
|
-
stripComments({ type: '
|
|
40
|
+
stripComments({ type: 'none' }),
|
|
41
|
+
// 'none' means to keep no comments
|
|
41
42
|
],
|
|
42
43
|
});
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
**Options**
|
|
46
47
|
|
|
47
|
-
* type: "none" | "keep-legal"
|
|
48
|
+
* type: "none" | "keep-legal" (default) - changes the behavior of the transform function
|
|
48
49
|
* **none** removes all comments
|
|
49
50
|
* **keep-legal** remove all commments except those which contain `@legal` or `@license`, a very good practice to allow open source to shine yes?
|
|
50
|
-
* **istanbul** (default) only remove comments that target istanbul code coverage instrumentation (EG: `/* istanbul ignore else @preserve */`)
|
|
51
51
|
* enforce: "pre" (default) | "post" - determines where in the compilation pipeline the plugin should work;
|
|
52
52
|
|
|
53
53
|
## Contributions
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const a={type:"keep-legal",enforce:"pre"},m=(n={})=>{const o={type:["none","keep-legal"].some(e=>e===n.type)?n.type:a.type,enforce:["pre","post"].some(e=>e===n.enforce)?n.enforce:a.enforce};return{name:"vite-plugin-strip-comments",enforce:o.enforce,apply:"build",transform(e,l){if(!l||l.includes("node_modules")||!/\.([jt]sx?)$/.test(l))return{code:e,map:null};let t=e,r;const p=Array.from(e.matchAll(/\/\*[\s\S]*?\*\/|\/\*\*.*?\*\/|(?<!https?:)\/\/.*(?=\n)?/gm));for(let s=0;s<p.length;s+=1)switch([r]=p[s],o.type){case"keep-legal":["@legal","@license"].some(c=>r.includes(c))||(t=t.replace(r,""));break;case"none":default:t=t.replace(r,"")}return{code:t,map:null}}}};module.exports=m;
|
|
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":["import { type Plugin } from \"vite\";\n\nexport type StripCommentsPlugin = Plugin<StripCommentsConfig> & {\n name: string;\n enforce: \"pre\" | \"post\" | undefined;\n transform: (\n code: string,\n id?: string,\n ) => {\n code: string;\n map: string | null;\n };\n};\n\nexport type StripCommentsConfig = {\n type: \"none\" | \"keep-legal\"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { type Plugin } from \"vite\";\n\nexport type StripCommentsPlugin = Plugin<StripCommentsConfig> & {\n name: string;\n enforce: \"pre\" | \"post\" | undefined;\n apply: \"build\";\n transform: (\n code: string,\n id?: string,\n ) => {\n code: string;\n map: string | null;\n };\n};\n\nexport type StripCommentsConfig = {\n type: \"none\" | \"keep-legal\";\n enforce: \"pre\" | \"post\" | undefined;\n};\n\nconst StripCommentsDefaultConfig: StripCommentsConfig = {\n type: \"keep-legal\",\n enforce: \"pre\",\n};\n\nconst stripComments = (cfg: Partial<StripCommentsConfig> = {}) => {\n const config: Partial<StripCommentsConfig> = {\n type:\n ([\"none\", \"keep-legal\"].some((x) => x === cfg.type)\n ? cfg.type\n : StripCommentsDefaultConfig.type),\n enforce:\n ([\"pre\", \"post\"].some((x) => x === cfg.enforce)\n ? cfg.enforce\n : StripCommentsDefaultConfig.enforce),\n };\n\n return {\n name: \"vite-plugin-strip-comments\",\n enforce: config.enforce,\n apply: \"build\",\n transform(code: string, id?: string): { code: string; map: null } {\n /* istanbul ignore if @preserve */\n if (!id || id.includes(\"node_modules\") || !/\\.([jt]sx?)$/.test(id)) {\n return { code, map: null };\n }\n let result = code;\n let match: string;\n\n const matchesArray = Array.from(code.matchAll(\n /\\/\\*[\\s\\S]*?\\*\\/|\\/\\*\\*.*?\\*\\/|(?<!https?:)\\/\\/.*(?=\\n)?/gm,\n ));\n\n for (let i = 0; i < matchesArray.length; i += 1) {\n // 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.replace(match, \"\");\n }\n break;\n case \"none\":\n default:\n result = result.replace(match, \"\");\n }\n }\n\n return { code: result, map: null };\n },\n } satisfies StripCommentsPlugin;\n};\n\nexport default stripComments;\n"],"names":["StripCommentsDefaultConfig","stripComments","cfg","config","x","code","id","result","match","matchesArray","i"],"mappings":"aAoBA,MAAMA,EAAkD,CACtD,KAAM,aACN,QAAS,KACX,EAEMC,EAAgB,CAACC,EAAoC,KAAO,CAChE,MAAMC,EAAuC,CAC3C,KACG,CAAC,OAAQ,YAAY,EAAE,KAAMC,GAAMA,IAAMF,EAAI,IAAI,EAC9CA,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,MAAO,QACP,UAAUE,EAAcC,EAA0C,CAE5D,GAAA,CAACA,GAAMA,EAAG,SAAS,cAAc,GAAK,CAAC,eAAe,KAAKA,CAAE,EACxD,MAAA,CAAE,KAAAD,EAAM,IAAK,IAAK,EAE3B,IAAIE,EAASF,EACTG,EAEE,MAAAC,EAAe,MAAM,KAAKJ,EAAK,SACnC,4DAAA,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,QAAQC,EAAO,EAAE,GAEnC,MACF,IAAK,OACL,QACWD,EAAAA,EAAO,QAAQC,EAAO,EAAE,CAAA,CAIvC,MAAO,CAAE,KAAMD,EAAQ,IAAK,IAAK,CAAA,CAErC,CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
declare const stripComments: (cfg?: Partial<StripCommentsConfig>) => {
|
|
2
2
|
name: string;
|
|
3
3
|
enforce: "pre" | "post" | undefined;
|
|
4
|
+
apply: "build";
|
|
4
5
|
transform(code: string, id?: string): {
|
|
5
6
|
code: string;
|
|
6
7
|
map: null;
|
|
@@ -9,7 +10,7 @@ declare const stripComments: (cfg?: Partial<StripCommentsConfig>) => {
|
|
|
9
10
|
export default stripComments;
|
|
10
11
|
|
|
11
12
|
declare type StripCommentsConfig = {
|
|
12
|
-
type: "none" | "keep-legal"
|
|
13
|
+
type: "none" | "keep-legal";
|
|
13
14
|
enforce: "pre" | "post" | undefined;
|
|
14
15
|
};
|
|
15
16
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
const
|
|
2
|
-
type: "
|
|
1
|
+
const a = {
|
|
2
|
+
type: "keep-legal",
|
|
3
3
|
enforce: "pre"
|
|
4
|
-
}, m = (
|
|
5
|
-
const
|
|
6
|
-
type: ["none", "keep-legal"
|
|
7
|
-
enforce: ["pre", "post"].some((e) => e ===
|
|
4
|
+
}, m = (n = {}) => {
|
|
5
|
+
const o = {
|
|
6
|
+
type: ["none", "keep-legal"].some((e) => e === n.type) ? n.type : a.type,
|
|
7
|
+
enforce: ["pre", "post"].some((e) => e === n.enforce) ? n.enforce : a.enforce
|
|
8
8
|
};
|
|
9
9
|
return {
|
|
10
10
|
name: "vite-plugin-strip-comments",
|
|
11
|
-
enforce:
|
|
11
|
+
enforce: o.enforce,
|
|
12
|
+
apply: "build",
|
|
12
13
|
transform(e, r) {
|
|
13
14
|
if (!r || r.includes("node_modules") || !/\.([jt]sx?)$/.test(r))
|
|
14
15
|
return { code: e, map: null };
|
|
15
|
-
let t = e,
|
|
16
|
-
const
|
|
17
|
-
/\/\*[\s\S]
|
|
16
|
+
let t = e, l;
|
|
17
|
+
const p = Array.from(e.matchAll(
|
|
18
|
+
/\/\*[\s\S]*?\*\/|\/\*\*.*?\*\/|(?<!https?:)\/\/.*(?=\n)?/gm
|
|
18
19
|
));
|
|
19
|
-
for (let s = 0; s <
|
|
20
|
-
switch ([
|
|
20
|
+
for (let s = 0; s < p.length; s += 1)
|
|
21
|
+
switch ([l] = p[s], o.type) {
|
|
21
22
|
case "keep-legal":
|
|
22
|
-
["@legal", "@license"].some((
|
|
23
|
-
break;
|
|
24
|
-
case "istanbul":
|
|
25
|
-
n.includes("istanbul") && (t = t.replace(n, ""));
|
|
23
|
+
["@legal", "@license"].some((c) => l.includes(c)) || (t = t.replace(l, ""));
|
|
26
24
|
break;
|
|
27
25
|
case "none":
|
|
28
26
|
default:
|
|
29
|
-
t = t.replace(
|
|
27
|
+
t = t.replace(l, "");
|
|
30
28
|
}
|
|
31
29
|
return { code: t, map: null };
|
|
32
30
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { type Plugin } from \"vite\";\n\nexport type StripCommentsPlugin = Plugin<StripCommentsConfig> & {\n name: string;\n enforce: \"pre\" | \"post\" | undefined;\n transform: (\n code: string,\n id?: string,\n ) => {\n code: string;\n map: string | null;\n };\n};\n\nexport type StripCommentsConfig = {\n type: \"none\" | \"keep-legal\"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { type Plugin } from \"vite\";\n\nexport type StripCommentsPlugin = Plugin<StripCommentsConfig> & {\n name: string;\n enforce: \"pre\" | \"post\" | undefined;\n apply: \"build\";\n transform: (\n code: string,\n id?: string,\n ) => {\n code: string;\n map: string | null;\n };\n};\n\nexport type StripCommentsConfig = {\n type: \"none\" | \"keep-legal\";\n enforce: \"pre\" | \"post\" | undefined;\n};\n\nconst StripCommentsDefaultConfig: StripCommentsConfig = {\n type: \"keep-legal\",\n enforce: \"pre\",\n};\n\nconst stripComments = (cfg: Partial<StripCommentsConfig> = {}) => {\n const config: Partial<StripCommentsConfig> = {\n type:\n ([\"none\", \"keep-legal\"].some((x) => x === cfg.type)\n ? cfg.type\n : StripCommentsDefaultConfig.type),\n enforce:\n ([\"pre\", \"post\"].some((x) => x === cfg.enforce)\n ? cfg.enforce\n : StripCommentsDefaultConfig.enforce),\n };\n\n return {\n name: \"vite-plugin-strip-comments\",\n enforce: config.enforce,\n apply: \"build\",\n transform(code: string, id?: string): { code: string; map: null } {\n /* istanbul ignore if @preserve */\n if (!id || id.includes(\"node_modules\") || !/\\.([jt]sx?)$/.test(id)) {\n return { code, map: null };\n }\n let result = code;\n let match: string;\n\n const matchesArray = Array.from(code.matchAll(\n /\\/\\*[\\s\\S]*?\\*\\/|\\/\\*\\*.*?\\*\\/|(?<!https?:)\\/\\/.*(?=\\n)?/gm,\n ));\n\n for (let i = 0; i < matchesArray.length; i += 1) {\n // 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.replace(match, \"\");\n }\n break;\n case \"none\":\n default:\n result = result.replace(match, \"\");\n }\n }\n\n return { code: result, map: null };\n },\n } satisfies StripCommentsPlugin;\n};\n\nexport default stripComments;\n"],"names":["StripCommentsDefaultConfig","stripComments","cfg","config","x","code","id","result","match","matchesArray","i"],"mappings":"AAoBA,MAAMA,IAAkD;AAAA,EACtD,MAAM;AAAA,EACN,SAAS;AACX,GAEMC,IAAgB,CAACC,IAAoC,OAAO;AAChE,QAAMC,IAAuC;AAAA,IAC3C,MACG,CAAC,QAAQ,YAAY,EAAE,KAAK,CAACC,MAAMA,MAAMF,EAAI,IAAI,IAC9CA,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,OAAO;AAAA,IACP,UAAUE,GAAcC,GAA0C;AAE5D,UAAA,CAACA,KAAMA,EAAG,SAAS,cAAc,KAAK,CAAC,eAAe,KAAKA,CAAE;AACxD,eAAA,EAAE,MAAAD,GAAM,KAAK,KAAK;AAE3B,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,QAAQC,GAAO,EAAE;AAEnC;AAAA,UACF,KAAK;AAAA,UACL;AACW,YAAAD,IAAAA,EAAO,QAAQC,GAAO,EAAE;AAAA,QAAA;AAIvC,aAAO,EAAE,MAAMD,GAAQ,KAAK,KAAK;AAAA,IAAA;AAAA,EAErC;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.5",
|
|
4
4
|
"description": "🗃️ Vite plugin for stripping comments in production builds",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/thednp/vite-plugin-strip-comments#readme",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/node": "^
|
|
32
|
-
"@vitest/coverage-istanbul": "^2.1.
|
|
33
|
-
"typescript": "^5.
|
|
31
|
+
"@types/node": "^22.10.6",
|
|
32
|
+
"@vitest/coverage-istanbul": "^2.1.8",
|
|
33
|
+
"typescript": "^5.7.3",
|
|
34
34
|
"vite": "^5.4.11",
|
|
35
|
-
"vite-plugin-dts": "^4.
|
|
36
|
-
"vitest": "^2.1.
|
|
35
|
+
"vite-plugin-dts": "^4.5.0",
|
|
36
|
+
"vitest": "^2.1.8"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=20",
|