vite.config.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /// <reference types="vitest" />
  2. import ViteYaml from '@modyfi/vite-plugin-yaml'
  3. import babel from '@rollup/plugin-babel'
  4. import react from '@vitejs/plugin-react'
  5. import * as path from 'node:path'
  6. import { visualizer } from 'rollup-plugin-visualizer'
  7. import { defineConfig } from 'vite'
  8. import checker from 'vite-plugin-checker'
  9. import {
  10. AtlasHtmlMetaTagsPlugin,
  11. AtlasWebmanifestPlugin,
  12. EmbeddedFallbackPlugin,
  13. OptimizePlugin,
  14. PolkadotWorkerMetaFixPlugin,
  15. } from './plugins'
  16. // https://vitejs.dev/config/
  17. export default defineConfig({
  18. root: './src',
  19. build: {
  20. target: ['chrome87', 'edge88', 'es2020', 'firefox78', 'safari14'],
  21. emptyOutDir: true,
  22. outDir: path.resolve(__dirname, 'dist'),
  23. rollupOptions: {
  24. input: {
  25. main: path.resolve(__dirname, 'src/index.html'),
  26. embedded: path.resolve(__dirname, 'src/embedded/index.html'),
  27. },
  28. },
  29. },
  30. server: {
  31. port: 3000,
  32. },
  33. test: {
  34. environment: 'happy-dom',
  35. setupFiles: ['vitest-setup.ts'],
  36. globals: true,
  37. },
  38. esbuild: {
  39. logOverride: { 'this-is-undefined-in-esm': 'silent' }, // workaround for vite, esbuild and babel integration bug: https://github.com/vitejs/vite/issues/8644
  40. },
  41. worker: {
  42. plugins: [PolkadotWorkerMetaFixPlugin],
  43. },
  44. plugins: [
  45. AtlasHtmlMetaTagsPlugin,
  46. AtlasWebmanifestPlugin,
  47. EmbeddedFallbackPlugin,
  48. OptimizePlugin,
  49. ViteYaml(),
  50. react({
  51. exclude: /\.stories\.[tj]sx?$/,
  52. }),
  53. checker({
  54. typescript: true,
  55. eslint: {
  56. lintCommand: 'eslint "./**/*.{js,jsx,ts,tsx}"',
  57. dev: { overrideConfig: { ignorePath: '../.eslintignore' } },
  58. },
  59. overlay: false,
  60. }),
  61. babel({
  62. extensions: ['.tsx', '.ts'],
  63. include: ['**/*.style.*', '**/*.styles.*'],
  64. plugins: ['@emotion'],
  65. babelHelpers: 'bundled',
  66. }),
  67. {
  68. ...visualizer({
  69. filename: 'dist/stats.html',
  70. }),
  71. enforce: 'post',
  72. },
  73. ],
  74. resolve: {
  75. alias: {
  76. '@': path.resolve(__dirname, './src'),
  77. },
  78. },
  79. optimizeDeps: {
  80. include: ['buffer'],
  81. esbuildOptions: {
  82. define: {
  83. global: 'globalThis',
  84. },
  85. },
  86. },
  87. })