Skip to content

Commit

Permalink
fix: use chunkFileNames default to avoid ssr assets in client folder (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Apr 18, 2024
1 parent b787f13 commit 9f266ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-boats-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/vite": patch
---

Switch to overriding the default chunkFileNames instead of assets dir to avoid server assets in client assets folder.
21 changes: 11 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,17 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
}
}

if (isSSRBuild && !config.build?.rollupOptions?.output) {
// 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 chunkFileNames config to instead output to the outDir directly.
config.build ??= {};
config.build.rollupOptions ??= {};
config.build.rollupOptions.output = {
chunkFileNames: `[name]-[hash].js`,
};
}

if (basePathVar) {
config.experimental ??= {};

Expand All @@ -310,16 +321,6 @@ 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;
Expand Down

0 comments on commit 9f266ff

Please sign in to comment.