VUE uses Webpack to configure different interface addresses for production environments and release environments

Source: Internet
Author: User

* forward to: http://blog.csdn.net/fungleo/article/details/54574049

The first step is to set a different interface address. First, we find the following file separately:/config/Dev.env.js/config/Prod.env.jsIn fact, these two files are files that set different parameters for the production environment and the publishing environment. We open the Dev.en.js file. The code is as follows:varMerge = require (' Webpack-merge ')varProdenv = require ('./prod.env ')) Module.exports=Merge (prodenv, {node_env:' "Development" '})OK, let's add an entry below the NODE_ENV code as follows:varMerge = require (' Webpack-merge ')varProdenv = require ('./prod.env ')) Module.exports=Merge (prodenv, {node_env:' "Development" ', Api_root:' "//192.168.1.8/api" '})then, we edit the Prod.env.js file, Module.exports={node_env:' "Production" ', Api_root:' "//www.baidu.com/api" '}good. The paths we set separately are already there. Here is the question of how to invoke it. In the second part, call the set parameters in the code as an example of our previous demo code. Please adjust your own project according to your own situation. The following files and codes are for informational purposes only. We open src/config/api.js file, the code that starts with the original//Configure API Interface addressvarroot = ' Https://cnodejs.org/api/v1 'modified to//Configure API Interface addressvarRoot =Process.env.API_ROOTthen we finished our configuration work. Finally, restarting the project will enable the newly configured interface address to take effect. After this configuration, we are running npm run dev1, the test interface is what runs. And we're running NPM run build1when packaging the project, the packaging is the official interface of the server, we do not have to tune to get it. Have a good time!

VUE uses Webpack to configure different interface addresses for production environments and release environments

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.