区别:Webpack CSS加载器和原始加载器

Luc*_*cia 3 sass loader webpack webpack-style-loader

So according to this question, css-loader loads file as string, resolves webpack dependency according to require, and style-loader inserts style tag into page, and in many cases, css-loader can be replaced by raw-loader.

I'm currently using:

loader: ExtractTextPlugin.extract("raw-loader!postcss-loader!sass-loader?sourceMap&" + sassIncludePaths.join(""))
Run Code Online (Sandbox Code Playgroud)

And there are requires in the .scss files, but I don't see a problem with raw-loader yet. So question is:

  1. What exactly is the difference between the two?
  2. What might be a problem if I were to replace css-loader with raw-loader in order to reduce run time?

Luc*_*cia 5

从我自己的理解:

raw-loader和之间的主要区别在于,css-loader前者按原样加载文件,而后者按webpack排序require。因此,通常的用例css-loader是将其与结合使用style-loader,从而在页面中插入一个标记,从而使其仅包含该页面上使用的样式。

但是,在我们的情况下,extractTextPlugin无论如何我们都将它们放入一个文件中,因此我们可以只使用raw-loader来节省几乎一半的时间。

同样,它也sass-loader解决了@imports,这是我们正在使用的唯一依赖项,因此设置应该是正确的。