vite.config.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import {defineConfig} from 'vitest/config';
  2. import solidPlugin from 'vite-plugin-solid';
  3. import handlebars from 'vite-plugin-handlebars';
  4. import basicSsl from '@vitejs/plugin-basic-ssl';
  5. import {visualizer} from 'rollup-plugin-visualizer';
  6. import checker from 'vite-plugin-checker';
  7. // import devtools from 'solid-devtools/vite'
  8. import autoprefixer from 'autoprefixer';
  9. import {resolve} from 'path';
  10. import {existsSync, copyFileSync} from 'fs';
  11. import {ServerOptions} from 'vite';
  12. import {watchLangFile} from './watch-lang.js';
  13. import path from 'path';
  14. const rootDir = resolve(__dirname);
  15. const ENV_LOCAL_FILE_PATH = path.join(rootDir, '.env.local');
  16. const isDEV = process.env.NODE_ENV === 'development';
  17. if(isDEV) {
  18. if(!existsSync(ENV_LOCAL_FILE_PATH)) {
  19. copyFileSync(path.join(rootDir, '.env.local.example'), ENV_LOCAL_FILE_PATH);
  20. }
  21. watchLangFile();
  22. }
  23. const handlebarsPlugin = handlebars({
  24. context: {
  25. title: 'Telegram Web',
  26. description: 'Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.',
  27. url: 'https://web.telegram.org/k/',
  28. origin: 'https://web.telegram.org/'
  29. }
  30. });
  31. const serverOptions: ServerOptions = {
  32. // host: '192.168.95.17',
  33. port: 8080,
  34. sourcemapIgnoreList(sourcePath, sourcemapPath) {
  35. return sourcePath.includes('node_modules') || sourcePath.includes('logger');
  36. }
  37. };
  38. const SOLID_SRC_PATH = 'src/solid/packages/solid';
  39. const SOLID_BUILT_PATH = 'src/vendor/solid';
  40. const USE_SOLID_SRC = false;
  41. const SOLID_PATH = USE_SOLID_SRC ? SOLID_SRC_PATH : SOLID_BUILT_PATH;
  42. const USE_OWN_SOLID = existsSync(resolve(rootDir, SOLID_PATH));
  43. const USE_SSL = false;
  44. const USE_SSL_CERTS = false;
  45. const NO_MINIFY = false;
  46. const SSL_CONFIG: any = USE_SSL_CERTS && USE_SSL && {
  47. name: '192.168.95.17',
  48. certDir: './certs/'
  49. };
  50. const ADDITIONAL_ALIASES = {
  51. 'solid-transition-group': resolve(rootDir, 'src/vendor/solid-transition-group')
  52. };
  53. if(USE_OWN_SOLID) {
  54. console.log('using own solid', SOLID_PATH, 'built', !USE_SOLID_SRC);
  55. } else {
  56. console.log('using original solid');
  57. }
  58. export default defineConfig({
  59. plugins: [
  60. // devtools({
  61. // /* features options - all disabled by default */
  62. // autoname: true // e.g. enable autoname
  63. // }),
  64. process.env.VITEST ? undefined : checker({
  65. typescript: true,
  66. eslint: {
  67. // for example, lint .ts and .tsx
  68. lintCommand: 'eslint "./src/**/*.{ts,tsx}" --ignore-pattern "/src/solid/*"',
  69. useFlatConfig: true
  70. }
  71. }),
  72. solidPlugin(),
  73. handlebarsPlugin as any,
  74. USE_SSL ? (basicSsl as any)(SSL_CONFIG) : undefined,
  75. visualizer({
  76. gzipSize: true,
  77. template: 'treemap'
  78. })
  79. ].filter(Boolean),
  80. test: {
  81. // include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)'],
  82. exclude: [
  83. '**/node_modules/**',
  84. '**/dist/**',
  85. '**/cypress/**',
  86. '**/.{idea,git,cache,output,temp}/**',
  87. '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
  88. '**/solid/**'
  89. ],
  90. // coverage: {
  91. // provider: 'v8',
  92. // reporter: ['text', 'lcov'],
  93. // include: ['src/**/*.ts', 'store/src/**/*.ts', 'web/src/**/*.ts'],
  94. // exclude: ['**/*.d.ts', 'src/server/*.ts', 'store/src/**/server.ts']
  95. // },
  96. environment: 'jsdom',
  97. testTransformMode: {web: ['.[jt]sx?$']},
  98. // otherwise, solid would be loaded twice:
  99. // deps: {registerNodeLoader: true},
  100. // if you have few tests, try commenting one
  101. // or both out to improve performance:
  102. threads: false,
  103. isolate: false,
  104. globals: true,
  105. setupFiles: ['./src/tests/setup.ts']
  106. },
  107. server: serverOptions,
  108. base: '',
  109. build: {
  110. target: 'es2020',
  111. sourcemap: true,
  112. assetsDir: '',
  113. copyPublicDir: false,
  114. emptyOutDir: true,
  115. minify: NO_MINIFY ? false : undefined,
  116. rollupOptions: {
  117. output: {
  118. sourcemapIgnoreList: serverOptions.sourcemapIgnoreList
  119. }
  120. // input: {
  121. // main: './index.html',
  122. // sw: './src/index.service.ts'
  123. // }
  124. }
  125. // cssCodeSplit: true
  126. },
  127. worker: {
  128. format: 'es'
  129. },
  130. css: {
  131. devSourcemap: true,
  132. postcss: {
  133. plugins: [
  134. autoprefixer({}) // add options if needed
  135. ]
  136. }
  137. },
  138. resolve: {
  139. // conditions: ['development', 'browser'],
  140. alias: USE_OWN_SOLID ? {
  141. 'rxcore': resolve(rootDir, SOLID_PATH, 'web/core'),
  142. 'solid-js/jsx-runtime': resolve(rootDir, SOLID_PATH, 'jsx'),
  143. 'solid-js/web': resolve(rootDir, SOLID_PATH, 'web'),
  144. 'solid-js/store': resolve(rootDir, SOLID_PATH, 'store'),
  145. 'solid-js': resolve(rootDir, SOLID_PATH),
  146. ...ADDITIONAL_ALIASES
  147. } : ADDITIONAL_ALIASES
  148. }
  149. });