vite.config.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { resolve } from 'path';
  2. import { defineConfig } from 'vite';
  3. import vue from '@vitejs/plugin-vue';
  4. import styleImport, { VantResolve } from 'vite-plugin-style-import';
  5. function pathResolve(dir) {
  6. return resolve(__dirname, dir);
  7. }
  8. // https://vitejs.dev/config/
  9. export default defineConfig({
  10. base: './',
  11. build: {
  12. outDir: 'dist/luckywheel'
  13. },
  14. resolve:{
  15. alias:[
  16. {
  17. find: '@',
  18. replacement: pathResolve('src'),
  19. }
  20. ],
  21. },
  22. plugins: [
  23. vue(),
  24. styleImport({
  25. // vant
  26. libs: [
  27. {
  28. libraryName: 'vant',
  29. esModule: true,
  30. // https://github.com/anncwb/vite-plugin-style-import/issues/52
  31. resolveStyle: (name) => `../es/${name}/style/index`,
  32. // resolveStyle: (name) => `../node_modules/vant/es/${name}/style/index`, // 如果报找不到vant可以改用上面的路径
  33. },
  34. ],
  35. // nutui
  36. // libs: [
  37. // {
  38. // libraryName: '@nutui/nutui',
  39. // libraryNameChangeCase: 'pascalCase',
  40. // resolveStyle: (name) => {
  41. // return `@nutui/nutui/dist/packages/${name}/index.scss`
  42. // }
  43. // }
  44. // ]
  45. }),
  46. ],
  47. css: {
  48. preprocessorOptions: {
  49. scss: {
  50. charset: false,
  51. // 配置 nutui 全局 scss 变量
  52. // additionalData: `@import "@nutui/nutui/dist/styles/variables.scss";`
  53. }
  54. }
  55. },
  56. server: {
  57. proxy: {
  58. // 字符串简写写法
  59. // '/api': 'http://www.myblog.com/api',
  60. // 选项写法
  61. '/app-api': {
  62. target: "https://ios.alipearlhair.com",//'http://www.myblog.com',
  63. changeOrigin: true, // 设置成false报错
  64. // rewrite: (path) => {
  65. // console.log(path,'ooooooooooooo');
  66. // path.replace(/^\/api/, '')
  67. // }
  68. },
  69. '/api': {
  70. target: "http://actapi.snjon.com",//'http://www.myblog.com',
  71. changeOrigin: true, // 设置成false报错
  72. // rewrite: (path) => {
  73. // console.log(path,'ooooooooooooo');
  74. // path.replace(/^\/api/, '')
  75. // }
  76. }
  77. // 正则表达式写法
  78. // '^/fallback/.*': {
  79. // target: 'http://jsonplaceholder.typicode.com',
  80. // changeOrigin: true,
  81. // rewrite: (path) => path.replace(/^\/fallback/, '')
  82. // }
  83. }
  84. }
  85. })