vite-plugin-strip-comments 0.0.5 → 0.0.7

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 CHANGED
@@ -4,12 +4,14 @@
4
4
  [![ci](https://github.com/thednp/vite-plugin-strip-comments/actions/workflows/ci.yml/badge.svg)](https://github.com/thednp/vite-plugin-strip-comments/actions/workflows/ci.yml)
5
5
  [![NPM Version](https://img.shields.io/npm/v/vite-plugin-strip-comments.svg)](https://www.npmjs.com/package/vite-plugin-strip-comments)
6
6
  [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-strip-comments.svg)](http://npm-stat.com/charts.html?package=vite-plugin-strip-comments)
7
- [![typescript version](https://img.shields.io/badge/typescript-5.7.3-brightgreen)](https://www.typescriptlang.org/)
8
- [![vitest version](https://img.shields.io/badge/vitest-2.1.8-brightgreen)](https://vitest.dev/)
9
- [![vite version](https://img.shields.io/badge/vite-5.4.11-brightgreen)](https://github.com/vitejs)
7
+ [![typescript version](https://img.shields.io/badge/typescript-5.9.3-brightgreen)](https://www.typescriptlang.org/)
8
+ [![vitest version](https://img.shields.io/badge/vitest-4.0.18-brightgreen)](https://vitest.dev/)
9
+ [![vite version](https://img.shields.io/badge/vite-7.3.1-brightgreen)](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**.
12
12
 
13
+ > NOTE - this plugin should be compatible with rollup, rolldown, tsup and tsdown as well.
14
+
13
15
  ## Install
14
16
 
15
17
  ```bash
@@ -45,10 +47,11 @@ export default defineConfig({
45
47
 
46
48
  **Options**
47
49
 
48
- * type: "none" | "keep-legal" (default) - changes the behavior of the transform function
50
+ * `type`: "none" | "keep-jsdoc" | "keep-legal" (default) - changes the behavior of the transform function
49
51
  * **none** removes all comments
50
- * **keep-legal** remove all commments except those which contain `@legal` or `@license`, a very good practice to allow open source to shine yes?
51
- * enforce: "pre" (default) | "post" - determines where in the compilation pipeline the plugin should work;
52
+ * **keep-legal** remove all commments except those which contain `@copyright`, `@legal` or `@license`, a very good practice to allow open source to shine yes?
53
+ * **keep-jsdoc** remove all commments except legal (described above) and JSDoc
54
+ * `enforce`: "pre" (default) | "post" - determines where in the compilation pipeline the plugin should work;
52
55
 
53
56
  ## Contributions
54
57
  * 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 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;
1
+ "use strict";const a={type:"keep-legal",enforce:"pre"},f=(n={})=>{const l={type:["none","keep-legal","keep-jsdoc"].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:l.enforce,apply:"build",transform(e,r){if(!r||r.includes("node_modules")||!/\.([jt]sx?)$/.test(r))return{code:e,map:null};let t=e,s;const c=Array.from(e.matchAll(/\/\*[\s\S]*?\*\/|\/\*\*.*?\*\/|(?<!https?:)\/\/.*(?=\n)?/gm));for(let o=0;o<c.length;o+=1){[s]=c[o];const i=s.startsWith("/**"),p=["@legal","@license","@copyright"].some(m=>s.includes(m));switch(l.type){case"keep-jsdoc":!i&&!p&&(t=t.replace(s,""));break;case"keep-legal":p||(t=t.replace(s,""));break;default:t=t.replace(s,"")}}return{code:t,map:null}}}};module.exports=f;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -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),\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"}
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\" | \"keep-jsdoc\";\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: [\"none\", \"keep-legal\", \"keep-jsdoc\"].some((x) => x === cfg.type)\n ? cfg.type\n : StripCommentsDefaultConfig.type,\n enforce: [\"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(\n code.matchAll(\n /\\/\\*[\\s\\S]*?\\*\\/|\\/\\*\\*.*?\\*\\/|(?<!https?:)\\/\\/.*(?=\\n)?/gm,\n ),\n );\n\n for (let i = 0; i < matchesArray.length; i += 1) {\n // first match\n [match] = matchesArray[i];\n const isJSDoc = match.startsWith(\"/**\");\n const isLegal = [\"@legal\", \"@license\", \"@copyright\"].some((x) =>\n match.includes(x)\n );\n // console.log({ isJSDoc, isLegal, match });\n\n switch (config.type) {\n case \"keep-jsdoc\":\n if (!isJSDoc && !isLegal) {\n result = result.replace(match, \"\");\n }\n break;\n case \"keep-legal\":\n if (!isLegal) {\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","isJSDoc","isLegal"],"mappings":"aAoBA,MAAMA,EAAkD,CACtD,KAAM,aACN,QAAS,KACX,EAEMC,EAAgB,CAACC,EAAoC,KAAO,CAChE,MAAMC,EAAuC,CAC3C,KAAM,CAAC,OAAQ,aAAc,YAAY,EAAE,KAAMC,GAAMA,IAAMF,EAAI,IAAI,EACjEA,EAAI,KACJF,EAA2B,KAC/B,QAAS,CAAC,MAAO,MAAM,EAAE,KAAMI,GAAMA,IAAMF,EAAI,OAAO,EAClDA,EAAI,QACJF,EAA2B,OAAA,EAGjC,MAAO,CACL,KAAM,6BACN,QAASG,EAAO,QAChB,MAAO,QACP,UAAUE,EAAcC,EAA0C,CAEhE,GAAI,CAACA,GAAMA,EAAG,SAAS,cAAc,GAAK,CAAC,eAAe,KAAKA,CAAE,EAC/D,MAAO,CAAE,KAAAD,EAAM,IAAK,IAAA,EAEtB,IAAIE,EAASF,EACTG,EAEJ,MAAMC,EAAe,MAAM,KACzBJ,EAAK,SACH,4DAAA,CACF,EAGF,QAASK,EAAI,EAAGA,EAAID,EAAa,OAAQC,GAAK,EAAG,CAE/C,CAACF,CAAK,EAAIC,EAAaC,CAAC,EACxB,MAAMC,EAAUH,EAAM,WAAW,KAAK,EAChCI,EAAU,CAAC,SAAU,WAAY,YAAY,EAAE,KAAMR,GACzDI,EAAM,SAASJ,CAAC,CAAA,EAIlB,OAAQD,EAAO,KAAA,CACb,IAAK,aACC,CAACQ,GAAW,CAACC,IACfL,EAASA,EAAO,QAAQC,EAAO,EAAE,GAEnC,MACF,IAAK,aACEI,IACHL,EAASA,EAAO,QAAQC,EAAO,EAAE,GAEnC,MAEF,QACED,EAASA,EAAO,QAAQC,EAAO,EAAE,CAAA,CAEvC,CAEA,MAAO,CAAE,KAAMD,EAAQ,IAAK,IAAA,CAC9B,CAAA,CAEJ"}
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ declare const stripComments: (cfg?: Partial<StripCommentsConfig>) => {
10
10
  export default stripComments;
11
11
 
12
12
  declare type StripCommentsConfig = {
13
- type: "none" | "keep-legal";
13
+ type: "none" | "keep-legal" | "keep-jsdoc";
14
14
  enforce: "pre" | "post" | undefined;
15
15
  };
16
16
 
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- const a = {
1
+ const p = {
2
2
  type: "keep-legal",
3
3
  enforce: "pre"
4
- }, m = (n = {}) => {
4
+ }, f = (n = {}) => {
5
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
6
+ type: ["none", "keep-legal", "keep-jsdoc"].some((e) => e === n.type) ? n.type : p.type,
7
+ enforce: ["pre", "post"].some((e) => e === n.enforce) ? n.enforce : p.enforce
8
8
  };
9
9
  return {
10
10
  name: "vite-plugin-strip-comments",
@@ -13,24 +13,33 @@ const a = {
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
- let t = e, l;
17
- const p = Array.from(e.matchAll(
18
- /\/\*[\s\S]*?\*\/|\/\*\*.*?\*\/|(?<!https?:)\/\/.*(?=\n)?/gm
19
- ));
20
- for (let s = 0; s < p.length; s += 1)
21
- switch ([l] = p[s], o.type) {
16
+ let t = e, s;
17
+ const a = Array.from(
18
+ e.matchAll(
19
+ /\/\*[\s\S]*?\*\/|\/\*\*.*?\*\/|(?<!https?:)\/\/.*(?=\n)?/gm
20
+ )
21
+ );
22
+ for (let l = 0; l < a.length; l += 1) {
23
+ [s] = a[l];
24
+ const m = s.startsWith("/**"), c = ["@legal", "@license", "@copyright"].some(
25
+ (i) => s.includes(i)
26
+ );
27
+ switch (o.type) {
28
+ case "keep-jsdoc":
29
+ !m && !c && (t = t.replace(s, ""));
30
+ break;
22
31
  case "keep-legal":
23
- ["@legal", "@license"].some((c) => l.includes(c)) || (t = t.replace(l, ""));
32
+ c || (t = t.replace(s, ""));
24
33
  break;
25
- case "none":
26
34
  default:
27
- t = t.replace(l, "");
35
+ t = t.replace(s, "");
28
36
  }
37
+ }
29
38
  return { code: t, map: null };
30
39
  }
31
40
  };
32
41
  };
33
42
  export {
34
- m as default
43
+ f as default
35
44
  };
36
45
  //# sourceMappingURL=index.mjs.map
@@ -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),\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;"}
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\" | \"keep-jsdoc\";\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: [\"none\", \"keep-legal\", \"keep-jsdoc\"].some((x) => x === cfg.type)\n ? cfg.type\n : StripCommentsDefaultConfig.type,\n enforce: [\"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(\n code.matchAll(\n /\\/\\*[\\s\\S]*?\\*\\/|\\/\\*\\*.*?\\*\\/|(?<!https?:)\\/\\/.*(?=\\n)?/gm,\n ),\n );\n\n for (let i = 0; i < matchesArray.length; i += 1) {\n // first match\n [match] = matchesArray[i];\n const isJSDoc = match.startsWith(\"/**\");\n const isLegal = [\"@legal\", \"@license\", \"@copyright\"].some((x) =>\n match.includes(x)\n );\n // console.log({ isJSDoc, isLegal, match });\n\n switch (config.type) {\n case \"keep-jsdoc\":\n if (!isJSDoc && !isLegal) {\n result = result.replace(match, \"\");\n }\n break;\n case \"keep-legal\":\n if (!isLegal) {\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","isJSDoc","isLegal"],"mappings":"AAoBA,MAAMA,IAAkD;AAAA,EACtD,MAAM;AAAA,EACN,SAAS;AACX,GAEMC,IAAgB,CAACC,IAAoC,OAAO;AAChE,QAAMC,IAAuC;AAAA,IAC3C,MAAM,CAAC,QAAQ,cAAc,YAAY,EAAE,KAAK,CAACC,MAAMA,MAAMF,EAAI,IAAI,IACjEA,EAAI,OACJF,EAA2B;AAAA,IAC/B,SAAS,CAAC,OAAO,MAAM,EAAE,KAAK,CAACI,MAAMA,MAAMF,EAAI,OAAO,IAClDA,EAAI,UACJF,EAA2B;AAAA,EAAA;AAGjC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAASG,EAAO;AAAA,IAChB,OAAO;AAAA,IACP,UAAUE,GAAcC,GAA0C;AAEhE,UAAI,CAACA,KAAMA,EAAG,SAAS,cAAc,KAAK,CAAC,eAAe,KAAKA,CAAE;AAC/D,eAAO,EAAE,MAAAD,GAAM,KAAK,KAAA;AAEtB,UAAIE,IAASF,GACTG;AAEJ,YAAMC,IAAe,MAAM;AAAA,QACzBJ,EAAK;AAAA,UACH;AAAA,QAAA;AAAA,MACF;AAGF,eAASK,IAAI,GAAGA,IAAID,EAAa,QAAQC,KAAK,GAAG;AAE/C,SAACF,CAAK,IAAIC,EAAaC,CAAC;AACxB,cAAMC,IAAUH,EAAM,WAAW,KAAK,GAChCI,IAAU,CAAC,UAAU,YAAY,YAAY,EAAE;AAAA,UAAK,CAACR,MACzDI,EAAM,SAASJ,CAAC;AAAA,QAAA;AAIlB,gBAAQD,EAAO,MAAA;AAAA,UACb,KAAK;AACH,YAAI,CAACQ,KAAW,CAACC,MACfL,IAASA,EAAO,QAAQC,GAAO,EAAE;AAEnC;AAAA,UACF,KAAK;AACH,YAAKI,MACHL,IAASA,EAAO,QAAQC,GAAO,EAAE;AAEnC;AAAA,UAEF;AACE,YAAAD,IAASA,EAAO,QAAQC,GAAO,EAAE;AAAA,QAAA;AAAA,MAEvC;AAEA,aAAO,EAAE,MAAMD,GAAQ,KAAK,KAAA;AAAA,IAC9B;AAAA,EAAA;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "name": "vite-plugin-strip-comments",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
+ "author": "thednp",
5
+ "license": "MIT",
4
6
  "description": "🗃️ Vite plugin for stripping comments in production builds",
5
7
  "main": "dist/index.mjs",
6
8
  "module": "./dist/index.mjs",
@@ -18,22 +20,24 @@
18
20
  },
19
21
  "keywords": [
20
22
  "vite",
23
+ "rollup",
24
+ "rolldown",
25
+ "tsup",
26
+ "tsdown",
21
27
  "strip",
22
28
  "comments"
23
29
  ],
24
- "author": "thednp",
25
- "license": "MIT",
26
30
  "bugs": {
27
31
  "url": "https://github.com/thednp/vite-plugin-strip-comments/issues"
28
32
  },
29
33
  "homepage": "https://github.com/thednp/vite-plugin-strip-comments#readme",
30
34
  "devDependencies": {
31
- "@types/node": "^22.10.6",
32
- "@vitest/coverage-istanbul": "^2.1.8",
33
- "typescript": "^5.7.3",
34
- "vite": "^5.4.11",
35
- "vite-plugin-dts": "^4.5.0",
36
- "vitest": "^2.1.8"
35
+ "@types/node": "^25.0.10",
36
+ "@vitest/coverage-istanbul": "^4.0.18",
37
+ "typescript": "^5.9.3",
38
+ "vite": "^7.3.1",
39
+ "vite-plugin-dts": "^4.5.4",
40
+ "vitest": "^4.0.18"
37
41
  },
38
42
  "engines": {
39
43
  "node": ">=20",
@@ -43,7 +47,7 @@
43
47
  "scripts": {
44
48
  "pre-test": "pnpm clean-coverage",
45
49
  "badges": "npx -p dependency-version-badge update-badge typescript vitest vite",
46
- "test": "pnpm pre-test && vitest --config vitest.config.mts",
50
+ "test": "pnpm pre-test && vitest --config vitest.config.ts",
47
51
  "clean-coverage": "rm -rf coverage .nyc_output",
48
52
  "format": "deno fmt src",
49
53
  "lint": "pnpm lint:ts && pnpm check:ts",
package/tsconfig.json CHANGED
@@ -1,36 +1,35 @@
1
- {
2
- // https://janessagarrow.com/blog/typescript-and-esbuild/
3
- "compilerOptions": {
4
- "lib": ["DOM", "ESNext", "DOM.Iterable"],
5
- // "types": ["vite", "vite/client"],
6
- "rootDir": "./",
7
- "baseUrl": "./",
8
- "module": "ESNext",
9
- "target": "ESNext",
10
- "moduleResolution": "Bundler",
11
- "allowJs": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "resolvePackageJsonImports": true,
14
- "useDefineForClassFields": true,
15
- "strict": true,
16
- "sourceMap": true,
17
- "resolveJsonModule": true,
18
- "esModuleInterop": true,
19
- "isolatedModules": true,
20
- "noUnusedLocals": true,
21
- "noUnusedParameters": true,
22
- "noImplicitReturns": true,
23
- "removeComments": false,
24
- "allowSyntheticDefaultImports": true,
25
- "noEmit": true,
26
- "checkJs": true,
27
- "skipLibCheck": true, // allows dts-bundle-generator to import from package.json
28
- "paths": {
29
- "~/*": [
30
- "./src/*"
31
- ],
32
- }
33
- },
34
- "include": ["src/*"],
35
- "exclude": ["node_modules", "experiments", "coverage", "dist"],
36
- }
1
+ {
2
+ // https://janessagarrow.com/blog/typescript-and-esbuild/
3
+ "compilerOptions": {
4
+ "lib": ["DOM", "ESNext", "DOM.Iterable"],
5
+ // "types": ["vite", "vite/client"],
6
+ "rootDir": "./",
7
+ "baseUrl": "./",
8
+ "module": "ESNext",
9
+ "target": "ESNext",
10
+ "moduleResolution": "Bundler",
11
+ "allowJs": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "resolvePackageJsonImports": true,
14
+ "useDefineForClassFields": true,
15
+ "strict": true,
16
+ "sourceMap": true,
17
+ "resolveJsonModule": true,
18
+ "esModuleInterop": true,
19
+ "isolatedModules": true,
20
+ "noUnusedLocals": true,
21
+ "noUnusedParameters": true,
22
+ "noImplicitReturns": true,
23
+ "removeComments": false,
24
+ "allowSyntheticDefaultImports": true,
25
+ "allowImportingTsExtensions": true,
26
+ "noEmit": true,
27
+ "checkJs": true,
28
+ "skipLibCheck": true, // allows dts-bundle-generator to import from package.json
29
+ "paths": {
30
+ "~/*": ["./src/*"],
31
+ },
32
+ },
33
+ "include": ["src/*"],
34
+ "exclude": ["node_modules", "experiments", "coverage", "dist"],
35
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { resolve } from "node:path";
2
+ import { defineConfig } from "vite";
3
+ import dts from "vite-plugin-dts";
4
+ import strip from "./src/index";
5
+
6
+ const NAME = "VitePluginStripComments";
7
+
8
+ const fileName = {
9
+ es: `index.mjs`,
10
+ cjs: `index.cjs`,
11
+ } as const;
12
+
13
+ export default defineConfig({
14
+ base: "./",
15
+ esbuild: {
16
+ legalComments: "none",
17
+ },
18
+ plugins: [
19
+ dts({
20
+ outDir: "dist",
21
+ copyDtsFiles: true,
22
+ rollupTypes: true,
23
+ }),
24
+ strip(),
25
+ ],
26
+ build: {
27
+ minify: "esbuild",
28
+ emptyOutDir: true,
29
+ outDir: "dist",
30
+ target: "ESNext",
31
+ lib: {
32
+ entry: resolve(__dirname, "src/index.ts"),
33
+ name: NAME,
34
+ formats: ["es", "cjs"],
35
+ fileName: (format) => fileName[format as "es" | "cjs"],
36
+ },
37
+ sourcemap: true,
38
+ },
39
+ });
@@ -0,0 +1,25 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ optimizeDeps: {
5
+ include: [
6
+ "@vitest/coverage-istanbul"
7
+ ]
8
+ },
9
+ esbuild: {
10
+ legalComments: 'inline',
11
+ },
12
+ build: {
13
+ minify: 'esbuild',
14
+ },
15
+ test: {
16
+ css: true,
17
+ globals: true,
18
+ coverage: {
19
+ provider: "istanbul",
20
+ reporter: ["html", "text", "lcov"],
21
+ enabled: true,
22
+ include: ["src/**/*.{ts,tsx}"],
23
+ },
24
+ },
25
+ });