Why is [name] always main in MiniCssExtractPlugin for webpack?

爱⌒轻易说出口 提交于 2021-02-05 09:12:47

问题


In webpack when configuring the MiniCssExtractPlugin, I don't understand why [name] is always "main"?

 plugins: [
   new MiniCssExtractPlugin({
      filename: 'assets/css/[name].css' // where does the name "main" come from?
    }) 
  ]

How could I pass a variable in so that [name] is the name of my app and not "main" without hardcoding it in like filename: 'assets/css/myapp.css' ?

Webpack output config:

module.exports = {
  entry: './src/app.js',
  output: {
    path: utils.resolve('/dist'),
  },

The wierd thing is that even Webpack creates the main bundle file as main.js. Why main?


回答1:


The [name] is the name of the entry point.

If the entry point is a String or Array webpack will use a a default entry name main, based on https://github.com/webpack/webpack/blob/6f413ae2e63897aef5e1956cb1c351ab33f6dbfe/lib/EntryOptionPlugin.js#L76.

You can provide your entry point as an object,

module.exports = {
  entry: { myName: './src/app.js'},
  output: {
    path: utils.resolve('/dist'),
  },
  ...
}

which will change entry name to myName.



来源:https://stackoverflow.com/questions/60139960/why-is-name-always-main-in-minicssextractplugin-for-webpack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!