Configuration issues for public request paths after packaging with Webpack

Source: Internet
Author: User

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

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.