vite.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import path from 'node:path'
  2. import { defineConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue2'
  4. import WindiCSS from 'vite-plugin-windicss'
  5. import Components from 'unplugin-vue-components/vite'
  6. import Icons from 'unplugin-icons/vite'
  7. import IconsResolver from 'unplugin-icons/resolver'
  8. import AutoImport from 'unplugin-auto-import/vite'
  9. import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
  10. import prefixer from 'postcss-prefix-selector'
  11. import basicSsl from '@vitejs/plugin-basic-ssl'
  12. const buildMap = {
  13. // 抽取vue等库
  14. external: {
  15. lib: {
  16. entry: path.resolve(__dirname, 'src/lib/main.ts'),
  17. name: 'JyLogin',
  18. fileName: 'jy-login-mini'
  19. },
  20. rollupOptions: {
  21. external: ['vue'],
  22. output: {
  23. globals: {
  24. vue: 'Vue'
  25. }
  26. }
  27. }
  28. },
  29. // 不抽取vue等库,全部打包到一起
  30. internal: {
  31. lib: {
  32. entry: path.resolve(__dirname, 'src/lib/main.ts'),
  33. name: 'JyLogin',
  34. fileName: 'jy-login'
  35. }
  36. }
  37. }
  38. // 参数 { mode: 'external', command: 'build', ssrBuild: false }
  39. export default ({ mode, command }) => {
  40. const buildDiff = buildMap[mode] || {}
  41. return defineConfig({
  42. resolve: {
  43. alias: {
  44. '@': `${path.resolve(__dirname, 'src')}`
  45. }
  46. },
  47. build: {
  48. target: 'chrome58',
  49. cssTarget: 'chrome58',
  50. minify: true,
  51. emptyOutDir: false,
  52. ...buildDiff
  53. },
  54. define: {
  55. 'process.env.NODE_ENV': '"production"'
  56. },
  57. css: {
  58. postcss: {
  59. plugins: [
  60. prefixer({
  61. prefix: '.plugin-login-auth-container',
  62. transform(prefix, selector, prefixedSelector, filePath, rule) {
  63. if (selector.match(/^(html|body)/))
  64. return selector.replace(/^([^\s]*)/, `$1 ${prefix}`)
  65. if (filePath.match(/node_modules/)) return selector
  66. const annotation = rule.prev()
  67. if (
  68. annotation?.type === 'comment' &&
  69. annotation.text.trim() === 'no-prefix'
  70. )
  71. return selector // Do not prefix style rules that are preceded by: /* no-prefix */
  72. return prefixedSelector
  73. }
  74. })
  75. ]
  76. }
  77. },
  78. plugins: [
  79. basicSsl(),
  80. vue(),
  81. WindiCSS(),
  82. Components({
  83. resolvers: [
  84. IconsResolver({
  85. componentPrefix: ''
  86. })
  87. ],
  88. dts: 'src/components.d.ts'
  89. }),
  90. Icons(),
  91. cssInjectedByJsPlugin(),
  92. AutoImport({
  93. imports: ['@vueuse/core'],
  94. dts: 'src/auto-imports.d.ts'
  95. })
  96. ],
  97. server: {
  98. https: true,
  99. host: true,
  100. port: 3333,
  101. proxy: {
  102. '/aiChat': {
  103. target: 'https://jybx3-webtest.jydev.jianyu360.com',
  104. changeOrigin: true
  105. },
  106. '/jyapi': {
  107. target: 'https://jybx3-webtest.jydev.jianyu360.com',
  108. changeOrigin: true
  109. },
  110. '/api': {
  111. target: 'https://jybx3-webtest.jydev.jianyu360.com',
  112. changeOrigin: true,
  113. rewrite: (path) => path.replace(/^\/api/, '')
  114. },
  115. '/front': {
  116. target: 'https://jybx3-webtest.jydev.jianyu360.com',
  117. changeOrigin: true
  118. },
  119. '/aiChat/ws': {
  120. target: 'ws://jybx3-webtest.jydev.jianyu360.com',
  121. changeOrigin: true,
  122. ws: true
  123. },
  124. '/ws': {
  125. target: 'wss://jybx3-webtest.jydev.jianyu360.com',
  126. changeOrigin: true,
  127. ws: true
  128. }
  129. }
  130. }
  131. })
  132. }