highjack minified builded dist folder to change a api backend target

谁说我不能喝 提交于 2021-02-11 12:47:25

问题


Explanation

i have a dist build of my Vue-CLI App. inside i am using .env vars to handle my Axios.baseURL for my entire APP. ofc in dev mode i am using a dev Backend and DB, in stage, using a mirror of master Backend and DB, and on master the correct Backend and DB for production.

what i want is to build with npm run build to create a stage (testable product) and then if the tests results positiv, move the whole dist folder to my production without changing anything of the dist folder, because i know the compiled stuff inside this very dist folder is ready for production.

then i need a config.js that changes the Axios.baseURL for this dist compiled folder afterwards to target the API Requests to another, my production Backend and DB

any ideas how to accomplish this? like a .env file but no .env file. i know it sounds confusing but this is what i need to do.


回答1:


Simplest thing to do is to use some shell utility (like sed) to simply "search and replace" the URL in the compiled js bundle...

If you really want do that without changing anything, only option is to remove the URL (or other config) from your app and make it external global variable declared by some other js file, which then needs to be included in the page before your app bundle. step by step

Search and replace seems much more straightforward tho....



来源:https://stackoverflow.com/questions/64661193/highjack-minified-builded-dist-folder-to-change-a-api-backend-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!