diff --git a/.changeset/lazy-eyes-enjoy.md b/.changeset/lazy-eyes-enjoy.md new file mode 100644 index 000000000000..1c3bf850b5fe --- /dev/null +++ b/.changeset/lazy-eyes-enjoy.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/enhanced-img': patch +--- + +fix: add script block only when there are imports to add diff --git a/packages/enhanced-img/src/vite-plugin.js b/packages/enhanced-img/src/vite-plugin.js index ad7326a62f71..e9eced264413 100644 --- a/packages/enhanced-img/src/vite-plugin.js +++ b/packages/enhanced-img/src/vite-plugin.js @@ -163,18 +163,18 @@ export function image_plugin(imagetools_plugin) { await Promise.all(pending_ast_updates); // add imports - let text = ''; if (imports.size) { + let text = ''; for (const [path, import_name] of imports.entries()) { text += `\timport ${import_name} from "${path}";\n`; } - } - if (ast.instance) { - // @ts-ignore - s.appendLeft(ast.instance.content.start, text); - } else { - s.prepend(`\n`); + if (ast.instance) { + // @ts-ignore + s.appendLeft(ast.instance.content.start, text); + } else { + s.prepend(`\n`); + } } if (ast.css) {