Webpack Official Document Analysis (iii): Entry points Detailed

Source: Internet
Author: User

1, there are many ways to define the entry property in the configuration of Webpack, in order to explain why it is useful to you, we will show you how to configure the entry property.

2. Single entry syntax

Usage:entry: string|Array<string>

Webpack.config.js

Module.exports = {  './path/to/my/entry/file.js '};

The above notation is the following shorthand:

Module.exports = {  entry: {    './path/to/my/entry/file.js '}  };

This is a good choice when you want to quickly set up a webpack configuration for an application or tool that has an entry point (IE: library). However, there is little flexibility in extending or extending the configuration using this syntax.

3. Object syntax

Usage:entry: {[entryChunkName: string]: string|Array<string>}

Webpack.config.js

Module.exports = {  entry: {    './src/app.js ',    './src/vendors.js '}  };

object syntax is more detailed. However, this is the most extensible way to define entries/entries in the application

4, the actual use of the program

(1) Separate application

Webpack.config.js

Module.exports = {  entry: {    './src/app.js ',    './src/vendors.js '}  };

Cause: This setting allows you to take advantage of CommonsChunkPlugin any vendor reference in the application package and extract it into the vendor bundle and replace it with a __webpack_require__() call. If there is no vendor code in the application package, you can implement a Common pattern called long-term vendor caching in Webpack .

(2) Multi-page application

Webpack.config.js

Module.exports = {  entry: {    './src/pageone/index.js ',    './src/pagetwo/ Index.js ',    './src/pagethree/index.js '  };

Reason:

in a multi-page application, the server extracts the new HTML document for you. The page reloads the new document, and the resource is reloaded. However, this gives us a unique opportunity to do more than one thing:

    • used to CommonsChunkPlugin Create a shared application code package between each page. as the number of entry points increases, multi-page applications that reuse a large number of code/modules between entry points can benefit from these technologies.

Webpack Official Document Analysis (iii): Entry points Detailed

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.