vite-plugin-strip-comments 0.0.4 → 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 +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +9 -9
- 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**.
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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]
|
|
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 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)
|
|
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.mjs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const
|
|
1
|
+
const a = {
|
|
2
2
|
type: "keep-legal",
|
|
3
3
|
enforce: "pre"
|
|
4
4
|
}, m = (n = {}) => {
|
|
5
|
-
const
|
|
6
|
-
type: ["none", "keep-legal"].some((e) => e === n.type) ? n.type :
|
|
7
|
-
enforce: ["pre", "post"].some((e) => e === n.enforce) ? n.enforce :
|
|
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
12
|
apply: "build",
|
|
13
13
|
transform(e, r) {
|
|
14
14
|
if (!r || r.includes("node_modules") || !/\.([jt]sx?)$/.test(r))
|
|
15
15
|
return { code: e, map: null };
|
|
16
16
|
let t = e, l;
|
|
17
|
-
const
|
|
18
|
-
/\/\*[\s\S]
|
|
17
|
+
const p = Array.from(e.matchAll(
|
|
18
|
+
/\/\*[\s\S]*?\*\/|\/\*\*.*?\*\/|(?<!https?:)\/\/.*(?=\n)?/gm
|
|
19
19
|
));
|
|
20
|
-
for (let
|
|
21
|
-
switch ([l] =
|
|
20
|
+
for (let s = 0; s < p.length; s += 1)
|
|
21
|
+
switch ([l] = p[s], o.type) {
|
|
22
22
|
case "keep-legal":
|
|
23
23
|
["@legal", "@license"].some((c) => l.includes(c)) || (t = t.replace(l, ""));
|
|
24
24
|
break;
|
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 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)
|
|
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": "^22.
|
|
32
|
-
"@vitest/coverage-istanbul": "^2.1.
|
|
33
|
-
"typescript": "^5.7.
|
|
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",
|