Skip to content

Commit

Permalink
fix: avoid asset transforms when not in linked mode (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Apr 11, 2024
1 parent 53e1bd4 commit 3818a34
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-spiders-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/vite": patch
---

Fix issue where asset related Marko taglibs / transforms were registered when not in linked mode (eg in tests)
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
output: "html",
};

if (linked) {
(ssrConfig as any).markoViteLinked = linked;
}

ssrCjsServeConfig = {
...ssrConfig,
ast: true,
Expand Down
10 changes: 6 additions & 4 deletions src/render-assets-transform.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { types } from "@marko/compiler";
export default (tag: types.NodePath<types.MarkoTag>, t: typeof types) => {
const body = tag.get("body");
const tagName = (tag.get("name").node as types.StringLiteral).value;
body.unshiftContainer("body", renderAssetsCall(t, `${tagName}-prepend`));
body.pushContainer("body", renderAssetsCall(t, tagName));
if ((tag.hub.file.markoOpts as any).markoViteLinked) {
const body = tag.get("body");
const tagName = (tag.get("name").node as types.StringLiteral).value;
body.unshiftContainer("body", renderAssetsCall(t, `${tagName}-prepend`));
body.pushContainer("body", renderAssetsCall(t, tagName));
}
};

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

0 comments on commit 3818a34

Please sign in to comment.