webpack中url-loader加载器[path]

'url-loader?limit=25000&name=path.[ext]'
打包后[path]指的是什么

阅读 2.4k
1 个回答

The [ext] portion of the query string you have mentioned is referring to the extension of the file.

This is actually not a feature of the loader itself, but rather a feature of all loaders via loader-utils

You can see as part of the documentation, that there are a variety of extra "string interpolation templates" that you can pass as a name property as part of the loader query.

The following tokens are replaced in the name parameter for any loader: (Also any time that resource is mentioned below, it means the fully resolved path of the file that the loader is operating on)

  • [ext] the extension of the resource

  • [name] the basename of the resource

  • [path] the path of the resource relative to the context query parameter or option.

  • [folder] the folder of the resource is in.

  • [emoji] a random emoji representation of options.content

  • [emoji:<length>] same as above, but with a customizable number of emojis

  • [hash] the hash of options.content (Buffer) (by default it's the hex digest of the md5 hash)

  • [<hashType>:hash:<digestType>:<length>] optionally one can configure

    • other hashTypes, i. e. sha1, md5, sha256, sha512

    • other digestTypes, i. e. hex, base26, base32, base36, base49, base52, base58, base62, base64

    • and length the length in chars

  • [N] the N-th match obtained from matching the current file name against options.regExp

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进