vite.config.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import react from "@vitejs/plugin-react";
  2. import { defineConfig } from "vite";
  3. import checker from "vite-plugin-checker";
  4. import tsconfigPaths from "vite-tsconfig-paths";
  5. import "vitest/config";
  6. import { execFile } from "node:child_process";
  7. const runLocaleScripts = () => {
  8. execFile("yarn", ["locale-compile"], (error, stdout, _stderr) => {
  9. if (error) {
  10. throw error;
  11. }
  12. console.log(stdout);
  13. execFile("yarn", ["locale-sort"], (error, stdout, _stderr) => {
  14. if (error) {
  15. throw error;
  16. }
  17. console.log(stdout);
  18. });
  19. });
  20. };
  21. // https://vitejs.dev/config/
  22. export default defineConfig({
  23. plugins: [
  24. {
  25. name: 'run-on-start',
  26. configureServer(_server) {
  27. runLocaleScripts();
  28. },
  29. },
  30. {
  31. name: "trigger-on-reload",
  32. configureServer(server) {
  33. server.watcher.on("change", (file) => {
  34. if (file.includes("locale/src")) {
  35. console.log(`File changed: ${file}, running locale scripts...`);
  36. runLocaleScripts();
  37. }
  38. });
  39. },
  40. },
  41. react(),
  42. checker({
  43. // e.g. use TypeScript check
  44. typescript: true,
  45. }),
  46. tsconfigPaths(),
  47. ],
  48. server: {
  49. host: true,
  50. port: 5173,
  51. strictPort: true,
  52. allowedHosts: true,
  53. },
  54. test: {
  55. environment: "happy-dom",
  56. setupFiles: ["./vitest-setup.js"],
  57. },
  58. assetsInclude: ["**/*.md", "**/*.png", "**/*.svg"],
  59. });