Skip to content

Commit dc0975b

Browse files
committed
Fix prod vite config
1 parent 20c14ed commit dc0975b

File tree

3 files changed

+64
-18
lines changed

3 files changed

+64
-18
lines changed

k8s/app-chart/values.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ codebattle:
1616
affinity: {}
1717
replicaCount: 1
1818
image:
19-
repository: codebattle/codebattle
19+
repository: hexlet-codebattle/codebattle
2020
imagePullPolicy: Always
2121
service:
2222
type: ClusterIP
@@ -30,32 +30,32 @@ runner:
3030
# Deployment or DaemonSet
3131
type: Deployment
3232
image:
33-
repository: codebattle/runner
33+
repository: hexlet-codebattle/runner
3434
imagePullPolicy: Always
3535

3636
chatbot:
37-
enabled: true
37+
enabled: false
3838
replicaCount: 1
3939
image:
40-
repository: codebattle/chat_bot
40+
repository: hexlet-codebattle/chat_bot
4141
imagePullPolicy: Always
4242
tag: "0.0.1"
4343

4444
nginx:
4545
image:
46-
repository: codebattle/nginx-assets
46+
repository: hexlet-codebattle/nginx-assets
4747
imagePullPolicy: Always
4848

4949
runnerRust:
5050
enabled: false
5151
langs:
5252
- name: rust
53-
image: codebattle/rust:1.76.0
53+
image: hexlet-codebattle/rust:1.76.0
5454
replicaCount: 1
5555
- name: js
56-
image: codebattle/js:20.11.1
56+
image: hexlet-codebattle/js:20.11.1
5757
replicaCount: 2
58-
- name: python
58+
- name: hexlet-python
5959
image: codebattle/python:3.12.2
6060
replicaCount: 3
6161

services/app/apps/codebattle/lib/codebattle_web/vite.ex

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,50 @@ defmodule CodebattleWeb.Vite do
1616
end
1717
end
1818

19-
def asset_path(entry) do
20-
case manifest()[entry] do
21-
%{"file" => file} -> "/assets/" <> file
22-
_ -> "/assets/" <> entry
19+
# Apply Phoenix digest hash to a path in production
20+
defp apply_digest(path) do
21+
if dev?() do
22+
path
23+
else
24+
# Use Phoenix's static path to get the digested version
25+
# Routes.static_path uses the endpoint's static_path/1
26+
CodebattleWeb.Endpoint.static_path(path)
2327
end
2428
end
2529

30+
def asset_path(entry) do
31+
path =
32+
case manifest()[entry] do
33+
%{"file" => file} -> "/assets/" <> file
34+
_ -> "/assets/" <> entry
35+
end
36+
37+
apply_digest(path)
38+
end
39+
2640
def css_paths(entry) do
27-
case manifest()[entry] do
28-
%{"css" => css_list} -> Enum.map(css_list, &("/assets/" <> &1))
29-
_ -> []
30-
end
41+
paths =
42+
case manifest()[entry] do
43+
%{"css" => css_list} ->
44+
# CSS imported by this JS entry
45+
Enum.map(css_list, &("/assets/" <> &1))
46+
47+
_ ->
48+
# No CSS imported by this entry, look for standalone CSS
49+
# Try to find a CSS file that matches the JS entry name
50+
# For "app.js", look for any entry that outputs "app.css"
51+
css_filename = String.replace(entry, ~r/\.js$/, ".css")
52+
53+
# Search through all manifest entries to find one with matching output
54+
case Enum.find(manifest(), fn {_k, v} ->
55+
is_map(v) && Map.get(v, "file") == css_filename
56+
end) do
57+
{_key, %{"file" => file}} -> ["/assets/" <> file]
58+
_ -> []
59+
end
60+
end
61+
62+
# Apply digest hash to all paths in production
63+
Enum.map(paths, &apply_digest/1)
3164
end
3265
end

services/app/apps/codebattle/vite.config.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const input = {
4444
landing: path.resolve(__dirname, "assets/js/landing.js"),
4545
external: path.resolve(__dirname, "assets/js/external.js"),
4646
styles: path.resolve(__dirname, "assets/css/style.scss"),
47+
// Note: landing.css and external.css use the same styles as app.css
48+
// Templates should reference app.css instead
4749
// broadcast_editor: path.resolve(__dirname, "assets/js/widgets/pages/broadcast-editor/index.js"),
4850
// stream: path.resolve(__dirname, "assets/js/widgets/pages/broadcast-editor/stream.js"),
4951
};
@@ -77,11 +79,22 @@ export default defineConfig(({ command, mode }) => ({
7779
build: {
7880
outDir: "priv/static/assets",
7981
assetsDir: "",
80-
manifest: true,
82+
manifest: "manifest.json",
8183
sourcemap: mode === "development",
8284
rollupOptions: {
8385
input,
84-
output: { manualChunks: { monaco: ["monaco-editor"] } },
86+
output: {
87+
entryFileNames: "[name].js",
88+
chunkFileNames: "[name]-[hash].js",
89+
assetFileNames: (assetInfo) => {
90+
// Rename styles.css to app.css for backwards compatibility
91+
if (assetInfo.name === 'styles.css') {
92+
return 'app.css';
93+
}
94+
return "[name].[ext]";
95+
},
96+
manualChunks: { monaco: ["monaco-editor"] },
97+
},
8598
},
8699
emptyOutDir: true,
87100
},

0 commit comments

Comments
 (0)