Skip to content

Commit 79b96b7

Browse files
authored
fix: add script block only when there are imports to add (#14604)
1 parent 313ee5e commit 79b96b7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

.changeset/lazy-eyes-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/enhanced-img': patch
3+
---
4+
5+
fix: add script block only when there are imports to add

packages/enhanced-img/src/vite-plugin.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,18 @@ export function image_plugin(imagetools_plugin) {
163163
await Promise.all(pending_ast_updates);
164164

165165
// add imports
166-
let text = '';
167166
if (imports.size) {
167+
let text = '';
168168
for (const [path, import_name] of imports.entries()) {
169169
text += `\timport ${import_name} from "${path}";\n`;
170170
}
171-
}
172171

173-
if (ast.instance) {
174-
// @ts-ignore
175-
s.appendLeft(ast.instance.content.start, text);
176-
} else {
177-
s.prepend(`<script>${text}</script>\n`);
172+
if (ast.instance) {
173+
// @ts-ignore
174+
s.appendLeft(ast.instance.content.start, text);
175+
} else {
176+
s.prepend(`<script>${text}</script>\n`);
177+
}
178178
}
179179

180180
if (ast.css) {

0 commit comments

Comments
 (0)