highjack缩小了生成的dist文件夹,以更改api后端目标 [英] highjack minified builded dist folder to change a api backend target
问题描述
我有我的Vue-CLI App的dist版本.在内部,我使用.env vars处理整个APP的Axios.baseURL.在 dev 模式下的Ofc我正在使用开发后端和数据库,在阶段中,使用主后端和数据库的镜像,并且在主上正确的后端和生产数据库.
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.
我想要的是使用 npm run build
进行构建以创建阶段(可测试的产品),然后如果测试结果为positiv,则将整个dist文件夹移至我的产品中,而无需更改任何dist文件夹,因为我知道此dist文件夹中的已编译内容已准备就绪.
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.
然后我需要一个config.js,该config.js之后将更改此dist编译文件夹的Axios.baseURL,以将API请求定向到另一个,我的生产后端和数据库
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
有什么想法可以做到这一点吗?类似于.env文件,但没有.env文件.我知道这听起来令人困惑,但这是我需要做的.
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.
推荐答案
Simplest thing to do is to use some shell utility (like sed) to simply "search and replace" the URL in the compiled js bundle...
如果您确实希望在不更改任何内容的情况下完成 ,唯一的选择是从应用中删除URL(或其他配置),并将其设置为 external 声明的全局变量一些其他js文件,然后需要在您的应用捆绑包之前将其包含在页面中.逐步
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....
这篇关于highjack缩小了生成的dist文件夹,以更改api后端目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!