From 94581a89998c4fff5d0360f9dc547198204a7d53 Mon Sep 17 00:00:00 2001 From: dec0dOS Date: Tue, 9 Jul 2024 19:58:54 +0100 Subject: [PATCH] fix: locales serving --- backend/app.js | 4 ++++ frontend/package.json | 3 ++- frontend/vite-plugin-generate-locales.js | 2 +- frontend/{vite.config.js => vite.config.mjs} | 16 +++++++++++++-- package.json | 2 ++ yarn.lock | 21 +++++++++++++++++--- 6 files changed, 41 insertions(+), 7 deletions(-) rename frontend/{vite.config.js => vite.config.mjs} (70%) diff --git a/backend/app.js b/backend/app.js index 9241761..db56c35 100644 --- a/backend/app.js +++ b/backend/app.js @@ -51,6 +51,10 @@ if ( ["/app", "/app/*"], express.static(path.join(__dirname, "..", "frontend", "build")) ); + app.use( + ["/locales", "/locales/*"], + express.static(path.join(__dirname, "..", "frontend", "build", "locales")) + ); app.get(["/app/network/*"], function (req, res) { res.sendFile(path.join(__dirname, "..", "frontend", "build", "index.html")); }); diff --git a/frontend/package.json b/frontend/package.json index e55d379..917d207 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -41,7 +41,8 @@ "rimraf": "^5.0.5", "source-map-explorer": "^2.5.3", "typescript": "^5.2.2", - "vite": "^4.4.11" + "vite": "^4.4.11", + "vite-plugin-static-copy": "^1.0.6" }, "scripts": { "start": "vite", diff --git a/frontend/vite-plugin-generate-locales.js b/frontend/vite-plugin-generate-locales.js index a2f4289..d501f91 100644 --- a/frontend/vite-plugin-generate-locales.js +++ b/frontend/vite-plugin-generate-locales.js @@ -4,7 +4,7 @@ import * as url from "url"; const __dirname = url.fileURLToPath(new URL(".", import.meta.url)); -export default function GenerateLocalesPlugin() { +export default function generateLocalesPlugin() { return { name: "generate-locales", buildStart() { diff --git a/frontend/vite.config.js b/frontend/vite.config.mjs similarity index 70% rename from frontend/vite.config.js rename to frontend/vite.config.mjs index d7fcd87..a69a8ab 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.mjs @@ -1,7 +1,8 @@ import process from "node:process"; import { defineConfig, searchForWorkspaceRoot } from "vite"; import react from "@vitejs/plugin-react"; -import GenerateLocalesPlugin from "./vite-plugin-generate-locales.js"; +import { viteStaticCopy } from "vite-plugin-static-copy"; +import generateLocalesPlugin from "./vite-plugin-generate-locales.js"; export default defineConfig({ base: "/app", @@ -29,5 +30,16 @@ export default defineConfig({ outDir: "build", chunkSizeWarningLimit: 1000, }, - plugins: [react(), GenerateLocalesPlugin()], + plugins: [ + react(), + generateLocalesPlugin(), + viteStaticCopy({ + targets: [ + { + src: "public/locales", + dest: "", + }, + ], + }), + ], }); diff --git a/package.json b/package.json index 3d09b03..42ae298 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,8 @@ "dev": "concurrently \"cd frontend && cross-env FAST_REFRESH=true yarn start\" \"cd backend && cross-env NODE_ENV=development ZU_DEFAULT_USERNAME=admin ZU_DEFAULT_PASSWORD=zero-ui nodemon ./bin/www --ignore data/db.json\"", "build": "cd frontend && cross-env GENERATE_SOURCEMAP=false yarn build", "prod": "cd backend && cross-env NODE_ENV=production ZU_SECURE_HEADERS=false yarn start", + "docker:build": "docker build . -t dec0dos/zero-ui -f docker/zero-ui/Dockerfile --progress=plain", + "docker:run": "docker run --rm --env-file .env -e ZU_CONTROLLER_ENDPOINT=http://host.docker.internal:9993 -p 4000:4000 --name zero-ui dec0dos/zero-ui", "release": "standard-version && git push --follow-tags origin main && git add CHANGELOG.md", "commit": "yarn git-cz" }, diff --git a/yarn.lock b/yarn.lock index 1218f1c..a3dfb0d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2376,7 +2376,7 @@ __metadata: languageName: node linkType: hard -"chokidar@npm:^3.5.2": +"chokidar@npm:^3.5.2, chokidar@npm:^3.5.3": version: 3.6.0 resolution: "chokidar@npm:3.6.0" dependencies: @@ -4246,7 +4246,7 @@ __metadata: languageName: node linkType: hard -"fast-glob@npm:^3.2.9": +"fast-glob@npm:^3.2.11, fast-glob@npm:^3.2.9": version: 3.3.2 resolution: "fast-glob@npm:3.3.2" dependencies: @@ -4535,6 +4535,7 @@ __metadata: styled-components: "npm:^5.3.11" typescript: "npm:^5.2.2" vite: "npm:^4.4.11" + vite-plugin-static-copy: "npm:^1.0.6" languageName: unknown linkType: soft @@ -4550,7 +4551,7 @@ __metadata: languageName: node linkType: hard -"fs-extra@npm:^11.0.0": +"fs-extra@npm:^11.0.0, fs-extra@npm:^11.1.0": version: 11.2.0 resolution: "fs-extra@npm:11.2.0" dependencies: @@ -9344,6 +9345,20 @@ __metadata: languageName: node linkType: hard +"vite-plugin-static-copy@npm:^1.0.6": + version: 1.0.6 + resolution: "vite-plugin-static-copy@npm:1.0.6" + dependencies: + chokidar: "npm:^3.5.3" + fast-glob: "npm:^3.2.11" + fs-extra: "npm:^11.1.0" + picocolors: "npm:^1.0.0" + peerDependencies: + vite: ^5.0.0 + checksum: 10c0/997114571bd429481974483465ab78d1ecd5fc48d2de06cbfe9dbf005f9b870aa072b0d9c22e2fd8def759db2c48ad662a6a0cdf47706fba409c82db7c03ed22 + languageName: node + linkType: hard + "vite@npm:^4.4.11": version: 4.5.3 resolution: "vite@npm:4.5.3"