问题
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