In our company, and in the backend interface, the public request path we are drawn separately, placed in a separate public.js, in the public.js to deposit that public variable
Public variables are like this
When using Ajax in other places, we use
This usage is not a problem in the usual project. But because the company's recent projects are used react to use, and then use Webpack to pack.
After the Webpack is packaged, public this JS is packaged into each component. If you need to change it, either modify it in each JS file after the react is packaged, or modify your public in Public.js
Path, and then package it again. It's going to be a lot of trouble.
The workaround is to create a Config.json file and place it in the root directory, because Webpack will not pack your JSON file, and then write it Config.json
{"Urlcontent": "http://www.dtvalue.com/consultation_market/"}
Change the code in my public.js to
$.urlcontent= "/http" +window.location.host+ "/consultation_market/"; $.ajax ({ URL: ' Config.json ', async: False, type: ' Get ', success:function (RS) { if (rs.urlcontent) { $.urlcontent=rs.urlcontent; }} );
So, with Webpack, when I need to change my public path, I don't need to be so troublesome, I just need to change the code in my Config.json
Here, $.ajax is going to synchronize instead of async, that is, async to false;
Original!
Configuration issues for public request paths after packaging with Webpack