What is the loader order for webpack?

前端 未结 3 1441
太阳男子
太阳男子 2020-12-02 06:26

When I have a loader configuration with multiple tests matching a file, I would expect only the first matching loader to be used but that doesn\'t seem to be the case.

3条回答
  •  心在旅途
    2020-12-02 07:13

    This answer was helpful to me but I'd like to complement with another point which affects loader order, which is the loadername! approach.

    Let's say you have an url-loader in your config with an higher priority than file-loader and you'd like to import an image path with the latter. Doing nothing would import the file via url-loader (which creates an encoded data-url).

    Prefixing the import with file-loader! would direct the import to that loader.

    import image from 'file-loader!./my-img.png'
    

提交回复
热议问题