前端项目打包后,部署到生产环境,经常需要修改静态资源的根路径和路由的根路径。最近,在学习Remix的时候找到了方法,打开vite.config.ts,相应的配置如下
export default defineConfig(({mode}) => {
const isProd=mode=='production'
return {
plugins: [
remix({
ssr: false,
future: {
v3_fetcherPersist: true,
v3_relativeSplatPath: true,
v3_throwAbortReason: true,
},
basename: isProd ? '/client' : '/'
}),
tsconfigPaths()
],
base:isProd ? '/client/' : '/'
}
});
其中,mode用于判断当前的环境,base用来设置静态资源的根路径,basename用来设置路由的根路径。