Webpack Tutorial (vi)--separating component code

Source: Internet
Author: User

Let's run the Webpack command first.

See App.js only 4k.

Install react

NPM Install react--sava-dev

Introducing react in the App/index.js file

Run Webpack

See that our App.js file has reached 100k.

Because the app.js contains a large amount of code for react, it causes the volume to increase.

If a user's internet speed is only 1k/s, and App.js has the process of loading CSS, such as the CSS file has not been separated out of the situation, the user will wait several minutes to see the entire page.

This is beyond endurance. How to solve it?

Add the following configuration in Webpack.config.js.

Executes the Webpack command.

The app.js has shrunk to 2k,react and separated into vendor.js.

Run it in the browser and see

Here to notice, the first request is vendor.js, after the request is app.js.

Webpack Tutorial (vi)--separating component code

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.