What's the use of webpack aliasfields?

Business background

  • in the process of using mpvue
  • found that his webpack configuration file contains the following line of code
  ...
  resolve: {
    ...
    aliasFields: ["mpvue", "weapp", "browser"],
  },

situation description

  • went to the official website to search, but it was relatively brief, and I didn"t understand
.

clipboard.png

  • official link to an English document https://github.com/defunctzom.
  • probably took a look at it, but I don"t quite understand
  • because of my limited English ability.

my question

  • does his browser have to be configured in package.json before it takes effect?
  • The function of
  • is equivalent to that if the content of alias is too complicated, can you separate it by aliasFields ?
Nov.29,2021

answer to question 1
the default value for aliasFields is ['browser'], so as long as the package.json of the referenced module has a browser field, webpack packages the module with an "alias" defined using the browser field. In a nutshell, the browser can only be produced in the package.json configuration of the referenced module, and only for this module .

answer to question 2
alias can be thought of as a global alias configuration, which replaces not only the source code of the project, but also the module referenced by it.

The content of
alias is too complex, so you can extract it through aliasFields and write it separately
.

it is not a big problem to elaborate on this point of view. But one thing to be clear is that aliasFields points to the package.json of the module rather than the pakcage.json of the current project.

To make a long story short, the difference between alias and aliasFields should be in scope. AliasFields can do fine granulation treatment.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e58572-4549f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e58572-4549f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?