You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.1 KiB

11 months ago
  1. import { defineConfig } from "vite"
  2. import { fileURLToPath, URL } from "url"
  3. import postcss from "./postcss.config.js"
  4. import react from "@vitejs/plugin-react"
  5. import dns from "dns"
  6. import { visualizer } from "rollup-plugin-visualizer"
  7. dns.setDefaultResultOrder("verbatim")
  8. // https://vitejs.dev/config/
  9. export default defineConfig({
  10. assetsInclude: [
  11. './public/piper/ort-wasm-simd-threaded.wasm',
  12. './public/piper/piper_phonemize.wasm',
  13. './public/piper/piper_phonemize.data',
  14. ],
  15. worker: {
  16. format: 'es'
  17. },
  18. server: {
  19. port: 3000,
  20. host: "localhost"
  21. },
  22. define: {
  23. "process.env": process.env
  24. },
  25. css: {
  26. postcss
  27. },
  28. plugins: [
  29. react(),
  30. visualizer({
  31. template: "treemap", // or sunburst
  32. open: false,
  33. gzipSize: true,
  34. brotliSize: true,
  35. filename: "bundleinspector.html" // will be saved in project's root
  36. })
  37. ],
  38. resolve: {
  39. alias: [
  40. {
  41. find: "@",
  42. replacement: fileURLToPath(new URL("./src", import.meta.url))
  43. },
  44. {
  45. process: "process/browser",
  46. stream: "stream-browserify",
  47. zlib: "browserify-zlib",
  48. util: "util",
  49. find: /^~.+/,
  50. replacement: (val) => {
  51. return val.replace(/^~/, "")
  52. }
  53. }
  54. ]
  55. },
  56. build: {
  57. rollupOptions: {
  58. output: {
  59. // These settings ensure the primary JS and CSS file references are always index.{js,css}
  60. // so we can SSR the index.html as text response from server/index.js without breaking references each build.
  61. entryFileNames: 'index.js',
  62. assetFileNames: (assetInfo) => {
  63. if (assetInfo.name === 'index.css') return `index.css`;
  64. return assetInfo.name;
  65. },
  66. },
  67. external: [
  68. // Reduces transformation time by 50% and we don't even use this variant, so we can ignore.
  69. /@phosphor-icons\/react\/dist\/ssr/,
  70. ]
  71. },
  72. commonjsOptions: {
  73. transformMixedEsModules: true
  74. }
  75. },
  76. optimizeDeps: {
  77. include: ["@mintplex-labs/piper-tts-web"],
  78. esbuildOptions: {
  79. define: {
  80. global: "globalThis"
  81. },
  82. plugins: []
  83. }
  84. }
  85. })