Webpack style-loader vs css-loader

后端 未结 4 649
误落风尘
误落风尘 2020-11-30 16:50

I have two questions.

1) CSS Loader and Style Loader are two webpack loaders. I couldn\'t grasp the difference between the two. Why do I have to use two loaders when

4条回答
  •  醉梦人生
    2020-11-30 17:13

    css-loader reads in a css file as a string. You could replace it with raw-loader and get the same effect in a lot of situations. Since it just reads the file contents and nothing else, it's basically useless unless you chain it with another loader.

    style-loader takes those styles and creates a

    That example comes from this tutorial. If you remove the style-loader from the pipeline by changing the line

    require("!style-loader!css-loader!./style.css");
    

    to

    require("css-loader!./style.css");
    

    you will see that the