Webpack's entry

Source: Internet
Author: User
Tags glob

Webpack has several options when it comes to packaging:

  Entry: "./app/entry",//String | Object | Array  entry: ["./app/entry1", "./app/entry2"],  entry: {    a: "./app/entry-a",    B: ["./app/entry-b1", ". /app/entry-b2 "]  },

For non-single-page applications, often choose the third way of writing, set multiple portals, this is not a problem, but sometimes more pages, maintenance of the entry object is very troublesome.

That's a different way of thinking, usually the page directory of items are regular, such as/src/pagea/index.js,/src/pageb/index.js, if you can keep such a name reading

We can get entry to find all of the [Pagename]/index.js portals and implement packaging.

var glob = require ("Glob"), var entries = Glob.sync ("./src/page/*/index.ts"). Reduce (function (prev, item) {    key = Item . replace (/\//g, ' _ '). Replace (/^\./, "). Replace (/^\_/,"). Replace (/\.js$/, ");    Prev[key] = Item;    return prev;}, {}); module.exports = {    entry:entries,    output: {        path:path.resolve (__dirname, "bin"),        FileName: "[name].js"    },    //...}

  

The function of the regular substitution here is to change the form like Src/page/projecta/index.js to Src_page_projecta_index (the value of the name variable) and output it to Bin/src_page_projecta_ Index.js.

Finish

Webpack's entry

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.