vue3的vite项目配置代理

vue3的vite项目配置代理

1.在vite.config.ts中配置以下代码

export default defineConfig({
  plugins: [
      //配置自动导入element start
      AutoImport({
          resolvers: [ElementPlusResolver()],
      }),
      Components({
          resolvers: [ElementPlusResolver()],
      }),
      createStyleImportPlugin({
          resolves: [ElementPlusResolve()],
          libs: [
              {
                  libraryName: 'element-plus',
                  esModule: true,
                  resolveStyle: (name: string) => {
                      return `element-plus/theme-chalk/${name}.css`
                  },
              },
          ]
      }),
      //配置自动导入element end
      vue(),

  ],
  //配置@符
  resolve:{
    alias:{
      "@":path.join(__dirname,"src"),
      "#":path.join(__dirname,"types")
    }
  },
  //配置代理,解决跨域问题
    server: {
        proxy: {
            "/api": {
                target: "http://localhost:3001",
                changeOrigin: true,
                //rewrite: (path) => path.replace(/^\/api/, ""),
            },
        },
    },

})
posted @ 2022-09-11 23:38  xiaowei123456  阅读(4174)  评论(0编辑  收藏  举报