vite.config.ts 4.2 KB

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