
只有在vite.config.js使用了,如下:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [path.resolve(process.cwd(), 'src/icon/svg')],
// 指定symbolId格式
symbolId: '[name]',
})
],
resolve: {
alias: {
'~': path.resolve(__dirname, './'),
'@': path.resolve(__dirname, 'src'),
}
},
server: {
proxy: {
'/api': {
target: 'http://2773c7b5.op', //接口域名
changeOrigin: true, //是否跨域
ws: false, //是否代理 websockets
// secure: true, //是否https接口
rewrite: path => path.replace(/^\/api/, '') //路径重置
// pathRewrite: { //路径重置
// '^/api': ''
// }
}
}
}
})
删除vite-plugin-svg-icons后,更改如下,仍报错:(全局都已经没有process了,但仍旧报错)
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
],
resolve: {
alias: {
'~': path.resolve(__dirname, './'),
'@': path.resolve(__dirname, 'src'),
}
},
server: {
proxy: {
'/api': {
target: 'http://2773c7b5.op', //接口域名
changeOrigin: true, //是否跨域
ws: false, //是否代理 websockets
// secure: true, //是否https接口
rewrite: path => path.replace(/^\/api/, '') //路径重置
// pathRewrite: { //路径重置
// '^/api': ''
// }
}
}
}
})
最后发现是path的原因
vue3不需要使用@来替代src路径,
所以更改如下:
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
],
// define这部分应该可以删除,但是我没删,也不报错了
define: {
'process.env': process.env
},
server: {
proxy: {
'/admin': {
target: 'http://shipin.jianjimall.cn/', //接口域名
changeOrigin: true, //是否跨域
ws: false, //是否代理 websockets
// secure: true, //是否https接口
// rewrite: path => path.replace(/^\/api/, '') //路径重置
pathRewrite: { //路径重置
'^/admin': ''
}
}
}
},
})
原本其他部分引入的是:
import { addUser } from '@/api/user.js'//接口
更改后:
import { addUser } from '/src/api/user.js'//接口
如果改了vite.config.js还报错process is not defined,请全局搜索process和path,并更改
7199

被折叠的 条评论
为什么被折叠?



