@richiesams/vitepress-plugin-images 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.
- package/dist/loader.js +1 -0
- package/dist/transform.js +9 -5
- package/package.json +3 -1
package/dist/loader.js
CHANGED
package/dist/transform.js
CHANGED
|
@@ -58,6 +58,9 @@ function transformTemplateContent(template, componentName) {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
export function transformOptimizedImages(code, id, componentName) {
|
|
61
|
+
if (id.includes("?")) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
61
64
|
const cleanId = id.split("?", 1)[0];
|
|
62
65
|
if (!cleanId.endsWith(".vue") && !cleanId.endsWith(".md")) {
|
|
63
66
|
return null;
|
|
@@ -74,11 +77,12 @@ export function transformOptimizedImages(code, id, componentName) {
|
|
|
74
77
|
const editor = new MagicString(code);
|
|
75
78
|
editor.overwrite(template.loc.start.offset, template.loc.end.offset, transformedTemplate.code);
|
|
76
79
|
const importBlock = `${transformedTemplate.imports.join("\n")}\n`;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
if (sfc.scriptSetup) {
|
|
81
|
+
const openTagEnd = code.indexOf(">", sfc.scriptSetup.loc.start.offset);
|
|
82
|
+
if (openTagEnd < 0) {
|
|
83
|
+
throw new Error(`[vitepress-plugin-images] Could not locate <script setup> tag end in ${cleanId}`);
|
|
84
|
+
}
|
|
85
|
+
editor.appendLeft(openTagEnd + 1, `\n${importBlock}`);
|
|
82
86
|
}
|
|
83
87
|
else {
|
|
84
88
|
editor.prepend(`<script setup>\n${importBlock}</script>\n`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@richiesams/vitepress-plugin-images",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Static image optimization pipeline for VitePress",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -40,7 +40,9 @@
|
|
|
40
40
|
"sharp": "^0.34.2"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
+
"@vitejs/plugin-vue": "^5.2.4",
|
|
43
44
|
"@types/node": "^26.1.0",
|
|
45
|
+
"@vue/server-renderer": "^3.5.17",
|
|
44
46
|
"tsx": "^4.20.3",
|
|
45
47
|
"typescript": "^5.8.3",
|
|
46
48
|
"vite": "^6.3.5",
|