vite-plugin-comment-delete 1.0.0

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/index.js +37 -0
  2. package/package.json +24 -0
package/index.js ADDED
@@ -0,0 +1,37 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export default function commentDelete() {
5
+ return {
6
+ name: "vite-plugin-comments-delete",
7
+ closeBundle() {
8
+ const distDir = path.resolve(__dirname, "dist");
9
+
10
+ const walk = (dir) => {
11
+ for (const file of fs.readdirSync(dir)) {
12
+ const fullPath = path.join(dir, file);
13
+ const stat = fs.statSync(fullPath);
14
+
15
+ if (stat.isDirectory()) {
16
+ walk(fullPath);
17
+ } else if (/\.(html|php)$/.test(file)) {
18
+ let content = fs.readFileSync(fullPath, "utf-8");
19
+
20
+ // HTMLコメント削除 <!-- -->
21
+ content = content.replace(/<!--[\s\S]*?-->/g, "");
22
+
23
+ // PHPコメント削除
24
+ content = content
25
+ .replace(/\/\*[\s\S]*?\*\//g, "") // /* */
26
+ .replace(/\/\/.*$/gm, "") // //
27
+ .replace(/#.*$/gm, ""); // #
28
+
29
+ fs.writeFileSync(fullPath, content);
30
+ }
31
+ }
32
+ };
33
+
34
+ walk(distDir);
35
+ },
36
+ };
37
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "vite-plugin-comment-delete",
3
+ "version": "1.0.0",
4
+ "description": "Build完了後にdist内に含まれるhtmlとphpのコメントアウトを削除する",
5
+ "main": "index.js",
6
+ "keywords": [
7
+ "vite",
8
+ "plugin"
9
+ ],
10
+ "author": "Koyo Code",
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "import": "./index.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "test": "echo \"Error: no test specified\" && exit 1"
20
+ },
21
+ "devDependencies": {
22
+ "vite": "^5.4.10"
23
+ }
24
+ }