webpack / webpack.js.org

Repository for webpack documentation and more!
https://webpack.js.org
Creative Commons Attribution 4.0 International
2.21k stars 3.31k forks source link

The behavior of `entry is array` should be described more specifically #3788

Open Jiang-Xuan opened 4 years ago

Jiang-Xuan commented 4 years ago

Feature request

What is the expected behavior?

The behavior of entry is array should be described more specifically

image

What is motivation or use case for adding/changing the behavior?

When the user sees the document, it should be clear how to use it and what the usage scenario is.

How should this be implemented in your opinion?

I think the document should be like this:

Array Syntax

module.exports = {
  entry: {
    main: ['react', 'react-dom']
  }
};

What happens when you pass an array to entry? Passing an array of file paths to the entry property creates what is known as a "multi-main entry". This is useful when you would like to inject multiple dependent files together and graph their dependencies into one "chunk".

another usage scenario is when you want inject a pollyfill or some special code, you can use array entry instead of import by hand.

example 1:

module.exports = {
  entry: {
    // have not to do `import('@babel/polyfill')` in entry.js file
    main: ['@babel/polyfill', './entry.js']
  }
};

example 2:

Common development environment configuration

module.exports = {
  entry: {
    // inject hot reload code
    main: ['webpack-dev-server/client?https://localhost:8080/', 'webpack/hot/dev-server', './entry.js']
  }
};

Are you willing to work on this yourself?

yes, but i do not good at english very well, i need help😄

chenxsan commented 4 years ago

I think you're referring to https://webpack.js.org/concepts/entry-points/#single-entry-shorthand-syntax. There's another page https://webpack.js.org/configuration/entry-context/#entry which covers more cases.

Jiang-Xuan commented 4 years ago

Missing usage: image

Jiang-Xuan commented 4 years ago

@chenxsan if you think i am wrong, feel free to close this issue 😉

mitchell-frost commented 4 years ago

I am willing to work on this issue...is it open?

Jiang-Xuan commented 4 years ago

@mitchell-frost Thanks, It is open 🍻
@chenxsan