Skip to content

Commit 3818a34

Browse files
authored
fix: avoid asset transforms when not in linked mode (#118)
1 parent 53e1bd4 commit 3818a34

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.changeset/proud-spiders-applaud.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@marko/vite": patch
3+
---
4+
5+
Fix issue where asset related Marko taglibs / transforms were registered when not in linked mode (eg in tests)

src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
209209
output: "html",
210210
};
211211

212+
if (linked) {
213+
(ssrConfig as any).markoViteLinked = linked;
214+
}
215+
212216
ssrCjsServeConfig = {
213217
...ssrConfig,
214218
ast: true,

src/render-assets-transform.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import type { types } from "@marko/compiler";
22
export default (tag: types.NodePath<types.MarkoTag>, t: typeof types) => {
3-
const body = tag.get("body");
4-
const tagName = (tag.get("name").node as types.StringLiteral).value;
5-
body.unshiftContainer("body", renderAssetsCall(t, `${tagName}-prepend`));
6-
body.pushContainer("body", renderAssetsCall(t, tagName));
3+
if ((tag.hub.file.markoOpts as any).markoViteLinked) {
4+
const body = tag.get("body");
5+
const tagName = (tag.get("name").node as types.StringLiteral).value;
6+
body.unshiftContainer("body", renderAssetsCall(t, `${tagName}-prepend`));
7+
body.pushContainer("body", renderAssetsCall(t, tagName));
8+
}
79
};
810

911
function renderAssetsCall(t: typeof types, slot: string) {

0 commit comments

Comments
 (0)