Skip to content

Commit c768910

Browse files
authored
add package.json exports field (#3903)
1 parent c10d90c commit c768910

File tree

7 files changed

+1347
-0
lines changed

7 files changed

+1347
-0
lines changed

examples/vite/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# jsPDF + Vite Test Project
2+
3+
This test project demonstrates that jsPDF now works correctly with Vite after the compatibility fix.
4+
5+
## Setup
6+
7+
```bash
8+
npm install
9+
```
10+
11+
## Development
12+
13+
```bash
14+
npm run dev
15+
```
16+
17+
Open http://localhost:5173 and click "Generate PDF" to test.
18+
19+
## Production Build
20+
21+
```bash
22+
npm run build
23+
npm run preview
24+
```
25+
26+
Open http://localhost:4173 and test the production build.
27+
28+
## What's Tested
29+
30+
- ✅ ES module import: `import { jsPDF } from "jspdf"`
31+
- ✅ PDF generation and download
32+
- ✅ Development server compatibility
33+
- ✅ Production build success
34+
35+
This confirms that GitHub issue #3851 has been resolved.

examples/vite/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + jsPDF Test</title>
8+
</head>
9+
<body>
10+
<div id="app">
11+
<h1>jsPDF + Vite Test</h1>
12+
<button id="generate-pdf">Generate PDF</button>
13+
<div id="status"></div>
14+
</div>
15+
<script type="module" src="/main.js"></script>
16+
</body>
17+
</html>

examples/vite/main.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { jsPDF } from "jspdf";
2+
3+
document.addEventListener("DOMContentLoaded", () => {
4+
const button = document.getElementById("generate-pdf");
5+
const status = document.getElementById("status");
6+
7+
button.addEventListener("click", () => {
8+
try {
9+
// Test that jsPDF import works
10+
const doc = new jsPDF();
11+
12+
doc.text(
13+
"Hello, this is a test PDF generated with jsPDF and Vite!",
14+
10,
15+
10
16+
);
17+
doc.text("If you can see this, the import issue has been fixed.", 10, 20);
18+
19+
// Save the PDF
20+
doc.save("test-vite-jspdf.pdf");
21+
22+
status.innerHTML =
23+
'<span style="color: green;">✅ Success! PDF generated successfully.</span>';
24+
status.innerHTML += "<br>jsPDF version: " + (doc.version || "unknown");
25+
} catch (error) {
26+
status.innerHTML =
27+
'<span style="color: red;">❌ Error: ' + error.message + "</span>";
28+
console.error("jsPDF Error:", error);
29+
}
30+
});
31+
32+
// Test that the import worked
33+
try {
34+
const testDoc = new jsPDF();
35+
status.innerHTML =
36+
'<span style="color: blue;">📦 jsPDF imported successfully! Click the button to test PDF generation.</span>';
37+
} catch (error) {
38+
status.innerHTML =
39+
'<span style="color: red;">❌ Import Error: ' + error.message + "</span>";
40+
}
41+
});

0 commit comments

Comments
 (0)