Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move default assets dir check to be unconditional #130

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/poor-dolphins-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/vite": patch
---

The previous patch of changing the default assetsDir for ssr was not applied in the correct branch. This is now fixed.
42 changes: 22 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
runtimeId,
});

if (isSSRBuild && !config.build?.ssrEmitAssets) {
config.build ??= {};

// For the server build vite will still output code split chunks to the `assets` directory by default.
// this is problematic since you might have server assets in your client assets folder.
// Here we change the default to be an empty string which makes the assetsDir essentially the same as
// as outDir for the server chunks.
config.build.assetsDir ??= "";
}

if (isTest) {
linked = false;
const { test } = config as any;
Expand Down Expand Up @@ -310,31 +320,23 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
);
}

if (isSSRBuild && !config.build?.ssrEmitAssets) {
config.build ??= {};

// For the server build vite will still output code split chunks to the `assets` directory by default.
// this is problematic since you might have server assets in your client assets folder.
// Here we change the default to be an empty string which makes the assetsDir essentially the same as
// as outDir for the server chunks.
config.build.assetsDir ??= "";
}

const assetsDir =
config.build?.assetsDir?.replace(/[/\\]$/, "") ?? "assets";
const assetsDirLen = assetsDir.length;
const assetsDirEnd = assetsDirLen + 1;
const trimAssertsDir = (fileName: string) => {
if (fileName.startsWith(assetsDir)) {
switch (fileName[assetsDirLen]) {
case POSIX_SEP:
case WINDOWS_SEP:
return fileName.slice(assetsDirEnd);
}
}
const trimAssertsDir = assetsDir
? (fileName: string) => {
if (fileName.startsWith(assetsDir)) {
switch (fileName[assetsDirLen]) {
case POSIX_SEP:
case WINDOWS_SEP:
return fileName.slice(assetsDirEnd);
}
}

return fileName;
};
return fileName;
}
: (fileName: string) => fileName;
config.experimental.renderBuiltUrl = (
fileName,
{ hostType, ssr },
Expand Down
Loading