Switch to nuxt assets for emojis (#311)

* switch to nuxt assets for emojis

* add auth to emoji endpoint

* fix cache control header

* fix type error
This commit is contained in:
Husky
2026-01-13 22:49:58 -05:00
committed by GitHub
parent 63ac2b8ffc
commit 1eaec4c3e8
8 changed files with 67 additions and 119 deletions

View File

@@ -1,9 +1,8 @@
import tailwindcss from "@tailwindcss/vite";
import { execSync } from "node:child_process";
import { cpSync, readFileSync, existsSync } from "node:fs";
import { readFileSync, existsSync } from "node:fs";
import path from "node:path";
import { findPackageJSON } from "node:module";
import { viteStaticCopy } from "vite-plugin-static-copy";
import module from "module";
import { type } from "arktype";
const packageJsonSchema = type({
@@ -11,6 +10,14 @@ const packageJsonSchema = type({
version: "string",
});
const twemojiJson = module.findPackageJSON(
"@discordapp/twemoji",
import.meta.url,
);
if (!twemojiJson) {
throw new Error("Could not find @discordapp/twemoji package.");
}
// get drop version
const dropVersion = getDropVersion();
@@ -56,7 +63,7 @@ export default defineNuxtConfig({
experimental: {
buildCache: true,
viewTransition: false,
viewTransition: true,
componentIslands: true,
},
@@ -68,39 +75,9 @@ export default defineNuxtConfig({
plugins: [
// eslint-disable-next-line @typescript-eslint/no-explicit-any
tailwindcss() as any,
// only used in dev server, not build because nitro sucks
// see build hook below
viteStaticCopy({
targets: [
{
src: "node_modules/@discordapp/twemoji/dist/svg/*",
dest: "twemoji",
},
],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}) as any,
],
},
hooks: {
"nitro:build:public-assets": (nitro) => {
const twemojiJson = findPackageJSON(
"@discordapp/twemoji",
import.meta.url,
);
if (!twemojiJson) {
throw new Error("Could not find @discordapp/twemoji package.");
}
// this is only run during build, not dev server
// https://github.com/nuxt/nuxt/issues/18918#issuecomment-1925774964
// copy emojis to .output/public/twemoji
const targetDir = path.join(nitro.options.output.publicDir, "twemoji");
cpSync(path.join(path.dirname(twemojiJson), "dist", "svg"), targetDir, {
recursive: true,
});
},
},
runtimeConfig: {
gitRef: commitHash,
dropVersion: dropVersion,
@@ -139,6 +116,7 @@ export default defineNuxtConfig({
scheduledTasks: {
"0 * * * *": ["dailyTasks"],
"*/30 * * * *": ["downloadCleanup"],
},
storage: {
@@ -154,6 +132,14 @@ export default defineNuxtConfig({
base: "./.data/appCache",
},
},
serverAssets: [
{
baseName: "twemoji",
// get path to twemoji svg assets
dir: path.join(path.dirname(twemojiJson), "dist", "svg"),
},
],
},
typescript: {