What's the idea of "layer" in Webpack 5?
Asked Answered
W

0

11

As title. I'm learning Webpack 5, and I just noticed there seems to be a concept called "layer" that is rarely mentioned(or I haven't found) in the documentation. It can be found here (for the intro. of top-level entry field):

    personal: {
      // ...
      layer: 'name of layer', // set the layer for an entry point
    },
  },
};

and here (for the built-in plugin SplitChunksPlugin):

splitChunks.cacheGroups.{cacheGroup}.layer

Assign modules to a cache group by module layer.

Are these two layers have the same meaning? If not, what are the definitions? Could you also point out the advantage(s) of using them? (I don't even know how to use it... at all)

Wideeyed answered 5/4, 2022 at 6:56 Comment(3)
It's also mentioned by webpack.js.org/configuration/module/#rulelayer : "Specify the layer in which the module should be placed in. A group of modules could be united in one layer which could then be used in split chunks, stats or entry options."Hydraulic
I'm going to guess that it's a way of grouping modules - I suppose as a kind of hint to Webpack how to split up modules?Ardellardella
@RichardHunter Now I have the same conclusion. I didn't have a deep dive into webpack when I asked the question.Wideeyed

© 2022 - 2024 — McMap. All rights reserved.