123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import { defineConfig } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import { resolve } from 'path'; // 主要用于alias文件路径别名
- function pathResolve(dir: string) {
- return resolve(__dirname, '.', dir);
- }
- // module.exports = {
- // devServer: {
- // proxy: {
- // '/api': {
- // target: 'http://127.0.0.1:8080/api', //接口域名
- // changeOrigin: true, //是否跨域
- // ws: true, //是否代理 websockets
- // secure: false, //是否https接口
- // pathRewrite: { //路径重置
- // '^/api': ''
- // }
- // }
- // }
- // }
- // };
- export default defineConfig({
- plugins: [vue()], // 配置需要使用的插件列表
- resolve: {
- alias: {
- "/@/": pathResolve("src")+'/', // 这里是将src目录配置别名为 /@ 方便在项目中导入src目录下的文件
- }
- },
- server: { //主要是加上这段代码
- host: '127.0.0.1',
- port: 3000,
- proxy: {
- '/api': {
- target: 'http://127.0.0.1:8080', //实际请求地址
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/api/, '')
- },
- }
- },
- css : {
- // css预处理器
- preprocessorOptions: {
- less: {
- charset: false,
- },
- },
- }
- })
|