@aippy/vite-plugins 0.2.0 → 0.2.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.
@@ -6,6 +6,7 @@ interface AssetPreloadOptions {
6
6
  outDir?: string;
7
7
  includeSubdirs?: boolean;
8
8
  deepScan?: boolean;
9
+ srcDir?: string;
9
10
  }
10
11
  export declare function aippyPreloadPlugin(options?: AssetPreloadOptions): Plugin;
11
12
  export default aippyPreloadPlugin;
@@ -15,6 +15,7 @@ class F {
15
15
  outDir: "dist",
16
16
  includeSubdirs: !0,
17
17
  deepScan: !0,
18
+ srcDir: "src",
18
19
  ...s
19
20
  };
20
21
  }
@@ -1,40 +1,65 @@
1
- import { existsSync as l } from "fs";
2
- import g from "path";
3
- const h = [".png", ".jpg", ".jpeg", ".gif", ".svg", ".webp"], m = [".mp4", ".webm", ".mov", ".avi"], w = [".mp3", ".wav", ".ogg", ".m4a"];
4
- function p(e) {
5
- return e.match(/^https?:\/\//) || e.match(/^data:/) || e.match(/^blob:/) || e.startsWith("/") ? e : `/${e}`;
1
+ import { existsSync as h } from "fs";
2
+ import f from "path";
3
+ const u = [".png", ".jpg", ".jpeg", ".gif", ".svg", ".webp"], w = [".mp4", ".webm", ".mov", ".avi"], d = [".mp3", ".wav", ".ogg", ".m4a"];
4
+ function g(e) {
5
+ return e.match(/^https?:\/\//) || e.match(/^data:/) || e.match(/^blob:/) || e.startsWith("/") ? e : `/${e.replace(/^(\.\.\/)+/, "").replace(/^\.\//, "")}`;
6
6
  }
7
- function E(e) {
8
- return !(e.includes("node_modules") || e.length < 4 || e.startsWith("./") && e.length < 10);
7
+ function p(e) {
8
+ if (!e || e.length < 4 || e.includes("node_modules") || e.startsWith("./") && e.length < 10)
9
+ return !1;
10
+ let t;
11
+ if (e.match(/^https?:\/\//)) {
12
+ const n = e.split("/");
13
+ t = n[n.length - 1];
14
+ } else {
15
+ const n = e.split("/");
16
+ t = n[n.length - 1];
17
+ }
18
+ if (t = t.split("?")[0].split("#")[0], !t || t.startsWith("."))
19
+ return !1;
20
+ const r = t.split(".");
21
+ return !(r.length < 2 || r[0].length === 0 || r[r.length - 1].toLowerCase() === "json");
9
22
  }
10
- function R(e, t = /* @__PURE__ */ new Set()) {
23
+ function A(e, t = /* @__PURE__ */ new Set()) {
11
24
  let r = "ASSET";
12
- h.some((n) => e.endsWith(n)) ? r = "IMAGE" : m.some((n) => e.endsWith(n)) ? r = "VIDEO" : w.some((n) => e.endsWith(n)) && (r = "AUDIO");
25
+ u.some((s) => e.endsWith(s)) ? r = "IMAGE" : w.some((s) => e.endsWith(s)) ? r = "VIDEO" : d.some((s) => e.endsWith(s)) && (r = "AUDIO");
13
26
  let o;
14
- const s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
27
+ const n = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
15
28
  do {
16
- let n = "";
29
+ let s = "";
17
30
  for (let c = 0; c < 4; c++)
18
- n += s[Math.floor(Math.random() * s.length)];
19
- o = `${r}_${n}`;
31
+ s += n[Math.floor(Math.random() * n.length)];
32
+ o = `${r}_${s}`;
20
33
  } while (t.has(o));
21
34
  return o;
22
35
  }
23
- function d(e, t, r = [".js", ".css", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".woff", ".woff2", ".ttf", ".eot"]) {
24
- const o = /* @__PURE__ */ new Set(), s = r.map((n) => n.replace(/^\./, "")).join("|");
36
+ function E(e) {
37
+ return e.replace(
38
+ /(["'])(?:(?=(\\?))\2.)*?\1|\/\*[\s\S]*?\*\/|\/\/.*/g,
39
+ (r) => r.startsWith('"') || r.startsWith("'") ? r : ""
40
+ );
41
+ }
42
+ function x(e) {
43
+ return e.replace(/\/\*[\s\S]*?\*\//g, "");
44
+ }
45
+ function S(e, t, r = [".js", ".css", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".woff", ".woff2", ".ttf", ".eot"]) {
46
+ const o = /* @__PURE__ */ new Set();
47
+ let n = e;
48
+ t === "js" ? n = E(e) : t === "css" && (n = x(e));
49
+ const s = r.map((c) => c.replace(/^\./, "")).join("|");
25
50
  if (t === "html")
26
51
  [
27
52
  // src/href attributes for img, script, link, video, audio tags
28
53
  new RegExp(`(?:src|href)=["']([^"']*\\.(?:${s}))["']`, "g"),
29
54
  // url() in CSS
30
55
  new RegExp(`url\\(["']?([^"']*\\.(?:${s}))["']?\\)`, "g")
31
- ].forEach((a) => {
32
- let i;
33
- for (; (i = a.exec(e)) !== null; )
34
- i[1] && o.add(p(i[1]));
35
- }), (e.match(/<script[^>]*>[\s\S]*?<\/script>/g) || []).forEach((a) => {
36
- const i = a.replace(/<script[^>]*>/, "").replace(/<\/script>/, "");
37
- d(i, "js", r).forEach((f) => o.add(f));
56
+ ].forEach((i) => {
57
+ let l;
58
+ for (; (l = i.exec(n)) !== null; )
59
+ l[1] && p(l[1]) && o.add(g(l[1]));
60
+ }), (n.match(/<script[^>]*>[\s\S]*?<\/script>/g) || []).forEach((i) => {
61
+ const l = i.replace(/<script[^>]*>/, "").replace(/<\/script>/, "");
62
+ S(l, "js", r).forEach((m) => o.add(m));
38
63
  });
39
64
  else if (t === "js")
40
65
  [
@@ -54,26 +79,26 @@ function d(e, t, r = [".js", ".css", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".
54
79
  new RegExp(`\\w+\\s*=\\s*["']([^"']*\\.(?:${s}))["']`, "g"),
55
80
  // Resource paths in string literals (more precise matching)
56
81
  new RegExp(`["']([^"']*\\.(?:${s}))["']`, "g")
57
- ].forEach((c) => {
58
- let a;
59
- for (; (a = c.exec(e)) !== null; )
60
- a[1] && E(a[1]) && o.add(p(a[1]));
82
+ ].forEach((a) => {
83
+ let i;
84
+ for (; (i = a.exec(n)) !== null; )
85
+ i[1] && p(i[1]) && o.add(g(i[1]));
61
86
  });
62
87
  else if (t === "css") {
63
- const n = new RegExp(`url\\(["']?([^"']*\\.(?:${s}))["']?\\)`, "g");
64
- let c;
65
- for (; (c = n.exec(e)) !== null; )
66
- c[1] && o.add(p(c[1]));
88
+ const c = new RegExp(`url\\(["']?([^"']*\\.(?:${s}))["']?\\)`, "g");
89
+ let a;
90
+ for (; (a = c.exec(n)) !== null; )
91
+ a[1] && p(a[1]) && o.add(g(a[1]));
67
92
  }
68
93
  return Array.from(o);
69
94
  }
70
- function S(e = process.cwd()) {
95
+ function I(e = process.cwd()) {
71
96
  try {
72
97
  let t = e, r = 0;
73
- for (; t !== g.parse(t).root && r < 20; ) {
74
- if (l(g.join(t, "package.json")))
98
+ for (; t !== f.parse(t).root && r < 20; ) {
99
+ if (h(f.join(t, "package.json")))
75
100
  return t;
76
- t = g.dirname(t), r++;
101
+ t = f.dirname(t), r++;
77
102
  }
78
103
  return process.cwd();
79
104
  } catch (t) {
@@ -81,9 +106,9 @@ function S(e = process.cwd()) {
81
106
  }
82
107
  }
83
108
  export {
84
- d as extractAssetsFromContent,
85
- S as findProjectRoot,
86
- R as generateConstantName,
87
- E as isValidAsset,
88
- p as processAssetURL
109
+ S as extractAssetsFromContent,
110
+ I as findProjectRoot,
111
+ A as generateConstantName,
112
+ p as isValidAsset,
113
+ g as processAssetURL
89
114
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/vite-plugins",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Vite plugins for Aippy projects - Asset management and component tagging",
5
5
  "private": false,
6
6
  "type": "module",