|
1 | 1 | import "./style.css"; |
2 | | -import { vendorName } from "./vendor"; |
3 | | - |
4 | | -console.log("Using vendor:", vendorName); |
5 | | - |
6 | | -// Display the current script's source (which contains the CID) |
7 | | -const script = document.querySelector('script[type="module"]'); |
8 | | -const display = document.querySelector("#cid-display"); |
9 | | - |
10 | | -if (script && display) { |
11 | | - const src = script.getAttribute("src"); |
12 | | - if (src) { |
13 | | - display.textContent = `Current Script: ${src}`; |
14 | | - |
15 | | - // Extract CID if present (simple regex check) |
16 | | - const cidMatch = src.match(/bafkrei[a-z0-9]+/); |
17 | | - if (cidMatch) { |
18 | | - display.innerHTML += |
19 | | - `<br><br><span style="color: #4ade80">✓ Verified CID: ${ |
20 | | - cidMatch[0] |
21 | | - }</span>`; |
| 2 | +async function main() { |
| 3 | + const { vendorName } = await import("./vendor"); |
| 4 | + |
| 5 | + console.log("Using vendor:", vendorName); |
| 6 | + |
| 7 | + // Display the current script's source (which contains the CID) |
| 8 | + const script = document.querySelector('script[type="module"]'); |
| 9 | + const display = document.querySelector("#cid-display"); |
| 10 | + |
| 11 | + if (script && display) { |
| 12 | + const src = script.getAttribute("src"); |
| 13 | + if (src) { |
| 14 | + display.textContent = `Current Script: ${src}`; |
| 15 | + |
| 16 | + // Extract CID if present (simple regex check) |
| 17 | + const cidMatch = src.match(/bafkrei[a-z0-9]+/); |
| 18 | + if (cidMatch) { |
| 19 | + display.innerHTML += |
| 20 | + `<br><br><span style="color: #4ade80">✓ Verified CID: ${ |
| 21 | + cidMatch[0] |
| 22 | + }</span>`; |
| 23 | + } |
22 | 24 | } |
23 | 25 | } |
24 | | -} |
25 | 26 |
|
26 | | -// Add a button to test dynamic import (which should generate a chunk) |
27 | | -const btn = document.createElement("button"); |
28 | | -btn.textContent = "Load Dynamic Chunk"; |
29 | | -btn.style.marginTop = "1rem"; |
30 | | -btn.style.padding = "0.5rem 1rem"; |
31 | | -btn.style.background = "#3B82F6"; |
32 | | -btn.style.color = "white"; |
33 | | -btn.style.border = "none"; |
34 | | -btn.style.borderRadius = "0.5rem"; |
35 | | -btn.style.cursor = "pointer"; |
36 | | - |
37 | | -btn.addEventListener("click", async () => { |
38 | | - const module = await import("./dynamic"); |
39 | | - console.log(module.msg); |
40 | | - alert(module.msg); |
41 | | -}); |
42 | | - |
43 | | -document.querySelector(".demo-section")?.appendChild(btn); |
44 | | - |
45 | | -console.log("CID Vite Plugin Playground Loaded"); |
| 27 | + // Add a button to test dynamic import (which should generate a chunk) |
| 28 | + const btn = document.createElement("button"); |
| 29 | + btn.textContent = "Load Dynamic Chunk"; |
| 30 | + btn.style.marginTop = "1rem"; |
| 31 | + btn.style.padding = "0.5rem 1rem"; |
| 32 | + btn.style.background = "#3B82F6"; |
| 33 | + btn.style.color = "white"; |
| 34 | + btn.style.border = "none"; |
| 35 | + btn.style.borderRadius = "0.5rem"; |
| 36 | + btn.style.cursor = "pointer"; |
| 37 | + |
| 38 | + btn.addEventListener("click", async () => { |
| 39 | + const module = await import("./dynamic"); |
| 40 | + console.log(module.msg); |
| 41 | + alert(module.msg); |
| 42 | + }); |
| 43 | + |
| 44 | + document.querySelector(".demo-section")?.appendChild(btn); |
| 45 | + |
| 46 | + console.log("CID Vite Plugin Playground Loaded"); |
| 47 | +} |
| 48 | +main(); |
0 commit comments