diff mrjunejune/BUILD @ 241:9c2eec61a152

[assets] Generate site images as WebP with Bazel
author MrJuneJune <me@mrjunejune.com>
date Mon, 03 Aug 2026 11:26:30 -0700
parents 1de6f553cbc0
children 543df0fe7168
line wrap: on
line diff
--- a/mrjunejune/BUILD	Mon Aug 03 10:48:59 2026 -0700
+++ b/mrjunejune/BUILD	Mon Aug 03 11:26:30 2026 -0700
@@ -1,7 +1,76 @@
 load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
 load("@rules_cc//cc:cc_library.bzl", "cc_library")
 load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
-load("//gui_ze:gui_ze.bzl", "move_files_into_dir", "bundle")
+load("//gui_ze:gui_ze.bzl", "move_files_into_dir", "bundle", "webp_image")
+
+_PNG_ASSETS = [
+  "23k",
+  "blue-noise-random",
+  "blue-noises-optimal",
+  "dog-treat",
+  "epi_all_colors",
+  "icon-192",
+  "icon-512",
+  "icon-maskable-512",
+  "logo_black",
+  "logo_white",
+  "logo_white_og",
+  "sprite_shiba0",
+  "sprite_shiba1",
+  "sprite_shiba2",
+  "sprite_shiba3",
+  "start-large",
+  "start-small-1",
+  "start-small-2",
+  "start-small-3",
+  "vscode",
+  "wabbit_alpha",
+  "white-noise-grass",
+]
+
+_LOSSLESS_WEBP_ASSETS = [
+  "dog-treat",
+  "epi_all_colors",
+  "icon-192",
+  "icon-512",
+  "icon-maskable-512",
+  "logo_black",
+  "logo_white",
+  "logo_white_og",
+  "sprite_shiba0",
+  "sprite_shiba1",
+  "sprite_shiba2",
+  "sprite_shiba3",
+  "start-large",
+  "start-small-1",
+  "start-small-2",
+  "start-small-3",
+  "wabbit_alpha",
+]
+
+[
+  webp_image(
+    name = "webp_{}".format(asset.replace("-", "_")),
+    src = "assets/png/{}.png".format(asset),
+    out = "generated_webp/{}.webp".format(asset),
+    lossless = asset in _LOSSLESS_WEBP_ASSETS,
+  )
+  for asset in _PNG_ASSETS
+]
+
+filegroup(
+  name = "generated_webp_assets",
+  srcs = [
+    ":webp_{}".format(asset.replace("-", "_"))
+    for asset in _PNG_ASSETS
+  ],
+)
+
+move_files_into_dir(
+  name = "generated_public_webp",
+  srcs = [":generated_webp_assets"],
+  dest = "src/public",
+)
 
 # Files
 move_files_into_dir(
@@ -47,7 +116,10 @@
 
 filegroup(
   name = "public_files",
-  srcs = glob(["src/public/*"]),
+  srcs = glob(
+    ["src/public/*"],
+    exclude = ["src/public/*.png"],
+  ) + [":generated_public_webp"],
   visibility = ["//visibility:public"],
 )
 
@@ -59,7 +131,10 @@
     
 filegroup(
   name = "src_files",
-  srcs = glob(["src/**"]) + [":react_pages", ":shared_js_non_public", ":shared_js_file", ":rich_editor_js", ":icons"],
+  srcs = glob(
+    ["src/**"],
+    exclude = ["src/**/*.png"],
+  ) + [":react_pages", ":shared_js_non_public", ":shared_js_file", ":rich_editor_js", ":icons", ":generated_public_webp"],
   visibility = ["//mrjunejune/test:__pkg__"],
 )