vite-plugin-comment-delete 1.0.1 → 1.1.1
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/index.js +9 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
-
import path from "
|
|
2
|
+
import path from "path";
|
|
3
3
|
|
|
4
|
-
export default function commentDelete() {
|
|
4
|
+
export default function commentDelete(outDir = "dist") {
|
|
5
5
|
return {
|
|
6
6
|
name: "vite-plugin-comments-delete",
|
|
7
7
|
closeBundle() {
|
|
8
|
-
const distDir = path.resolve(
|
|
8
|
+
const distDir = path.resolve(process.cwd(), outDir);
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(distDir)) return;
|
|
9
11
|
|
|
10
12
|
const walk = (dir) => {
|
|
11
13
|
for (const file of fs.readdirSync(dir)) {
|
|
@@ -17,14 +19,14 @@ export default function commentDelete() {
|
|
|
17
19
|
} else if (/\.(html|php)$/.test(file)) {
|
|
18
20
|
let content = fs.readFileSync(fullPath, "utf-8");
|
|
19
21
|
|
|
20
|
-
// HTMLコメント削除
|
|
22
|
+
// HTMLコメント削除
|
|
21
23
|
content = content.replace(/<!--[\s\S]*?-->/g, "");
|
|
22
24
|
|
|
23
25
|
// PHPコメント削除
|
|
24
26
|
content = content
|
|
25
|
-
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
26
|
-
.replace(/\/\/.*$/gm, "")
|
|
27
|
-
.replace(/#.*$/gm, "");
|
|
27
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
28
|
+
.replace(/\/\/.*$/gm, "")
|
|
29
|
+
.replace(/#.*$/gm, "");
|
|
28
30
|
|
|
29
31
|
fs.writeFileSync(fullPath, content);
|
|
30
32
|
}
|