@aippy/vite-plugins 0.2.5 → 0.2.6
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/dist/utils/index.js +46 -45
- package/package.json +1 -1
package/dist/utils/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { existsSync as
|
|
1
|
+
import { existsSync as m } from "fs";
|
|
2
2
|
import f from "path";
|
|
3
|
-
const
|
|
4
|
-
function
|
|
3
|
+
const g = [".png", ".jpg", ".jpeg", ".gif", ".svg", ".webp"], d = [".mp4", ".webm", ".mov", ".avi"], w = [".mp3", ".wav", ".ogg", ".m4a"];
|
|
4
|
+
function p(t) {
|
|
5
5
|
return t = t.trim(), t.match(/^https?:\/\//) || t.match(/^data:/) || t.match(/^blob:/), t;
|
|
6
6
|
}
|
|
7
7
|
function h(t) {
|
|
@@ -9,29 +9,30 @@ function h(t) {
|
|
|
9
9
|
return !1;
|
|
10
10
|
let e;
|
|
11
11
|
if (t.match(/^https?:\/\//)) {
|
|
12
|
-
const
|
|
13
|
-
e =
|
|
12
|
+
const c = t.split("?")[0].split("#")[0].split("/");
|
|
13
|
+
e = c[c.length - 1];
|
|
14
14
|
} else {
|
|
15
|
-
const
|
|
16
|
-
e =
|
|
15
|
+
const n = t.split("/");
|
|
16
|
+
e = n[n.length - 1], e = e.split("?")[0].split("#")[0];
|
|
17
17
|
}
|
|
18
|
-
if (
|
|
18
|
+
if (!e || e.startsWith("."))
|
|
19
19
|
return !1;
|
|
20
20
|
const s = e.split(".");
|
|
21
21
|
return !(s.length < 2 || s[0].length === 0 || s[s.length - 1].toLowerCase() === "json");
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function I(t, e = /* @__PURE__ */ new Set()) {
|
|
24
24
|
let s = "ASSET";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const i = t.split("?")[0].split("#")[0];
|
|
26
|
+
g.some((r) => i.endsWith(r)) ? s = "IMAGE" : d.some((r) => i.endsWith(r)) ? s = "VIDEO" : w.some((r) => i.endsWith(r)) && (s = "AUDIO");
|
|
27
|
+
let n;
|
|
28
|
+
const c = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
28
29
|
do {
|
|
29
|
-
let
|
|
30
|
-
for (let
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} while (e.has(
|
|
34
|
-
return
|
|
30
|
+
let r = "";
|
|
31
|
+
for (let o = 0; o < 4; o++)
|
|
32
|
+
r += c[Math.floor(Math.random() * c.length)];
|
|
33
|
+
n = `${s}_${r}`;
|
|
34
|
+
} while (e.has(n));
|
|
35
|
+
return n;
|
|
35
36
|
}
|
|
36
37
|
function E(t) {
|
|
37
38
|
return t.replace(
|
|
@@ -43,42 +44,42 @@ function S(t) {
|
|
|
43
44
|
return t.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
44
45
|
}
|
|
45
46
|
function j(t, e, s = [".js", ".css", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".woff", ".woff2", ".ttf", ".eot"]) {
|
|
46
|
-
const
|
|
47
|
-
let
|
|
48
|
-
e === "js" ?
|
|
49
|
-
const
|
|
47
|
+
const i = /* @__PURE__ */ new Set();
|
|
48
|
+
let n = t;
|
|
49
|
+
e === "js" ? n = E(t) : e === "css" && (n = S(t));
|
|
50
|
+
const c = s.map((r) => r.replace(/^\./, "")).join("|");
|
|
50
51
|
if (e === "html")
|
|
51
52
|
[
|
|
52
53
|
// src/href attributes for img, script, link, video, audio tags
|
|
53
|
-
new RegExp(`(?:src|href)=["']([^"']*\\.(?:${
|
|
54
|
+
new RegExp(`(?:src|href)=["']([^"']*\\.(?:${c})(?:[?#][^"']*)?)["']`, "g"),
|
|
54
55
|
// url() in CSS
|
|
55
|
-
new RegExp(`url\\(["']?([^"']*\\.(?:${
|
|
56
|
-
].forEach((
|
|
57
|
-
let
|
|
58
|
-
for (; (
|
|
59
|
-
|
|
60
|
-
}), (
|
|
61
|
-
const
|
|
62
|
-
j(
|
|
56
|
+
new RegExp(`url\\(["']?([^"']*\\.(?:${c})(?:[?#][^"']*)?)["']?\\)`, "g")
|
|
57
|
+
].forEach((a) => {
|
|
58
|
+
let l;
|
|
59
|
+
for (; (l = a.exec(n)) !== null; )
|
|
60
|
+
l[1] && h(l[1]) && i.add(p(l[1]));
|
|
61
|
+
}), (n.match(/<script[^>]*>[\s\S]*?<\/script>/g) || []).forEach((a) => {
|
|
62
|
+
const l = a.replace(/<script[^>]*>/, "").replace(/<\/script>/, "");
|
|
63
|
+
j(l, "js", s).forEach((u) => i.add(u));
|
|
63
64
|
});
|
|
64
65
|
else if (e === "js") {
|
|
65
|
-
const
|
|
66
|
-
let
|
|
67
|
-
for (; (
|
|
68
|
-
|
|
66
|
+
const r = new RegExp(`["']([^"']*\\.(?:${c})(?:[?#][^"']*)?)["']`, "g");
|
|
67
|
+
let o;
|
|
68
|
+
for (; (o = r.exec(n)) !== null; )
|
|
69
|
+
o[1] && h(o[1]) && i.add(p(o[1]));
|
|
69
70
|
} else if (e === "css") {
|
|
70
|
-
const
|
|
71
|
-
let
|
|
72
|
-
for (; (
|
|
73
|
-
|
|
71
|
+
const r = new RegExp(`url\\(["']?([^"']*\\.(?:${c})(?:[?#][^"']*)?)["']?\\)`, "g");
|
|
72
|
+
let o;
|
|
73
|
+
for (; (o = r.exec(n)) !== null; )
|
|
74
|
+
o[1] && h(o[1]) && i.add(p(o[1]));
|
|
74
75
|
}
|
|
75
|
-
return Array.from(
|
|
76
|
+
return Array.from(i);
|
|
76
77
|
}
|
|
77
|
-
function
|
|
78
|
+
function C(t = process.cwd()) {
|
|
78
79
|
try {
|
|
79
80
|
let e = t, s = 0;
|
|
80
81
|
for (; e !== f.parse(e).root && s < 20; ) {
|
|
81
|
-
if (
|
|
82
|
+
if (m(f.join(e, "package.json")))
|
|
82
83
|
return e;
|
|
83
84
|
e = f.dirname(e), s++;
|
|
84
85
|
}
|
|
@@ -89,8 +90,8 @@ function N(t = process.cwd()) {
|
|
|
89
90
|
}
|
|
90
91
|
export {
|
|
91
92
|
j as extractAssetsFromContent,
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
C as findProjectRoot,
|
|
94
|
+
I as generateConstantName,
|
|
94
95
|
h as isValidAsset,
|
|
95
|
-
|
|
96
|
+
p as processAssetURL
|
|
96
97
|
};
|