为什么样式加载器包含在我的生产包中?

cia*_*ben 7 javascript webpack webpack-style-loader css-loader

我有一个最小的webpack设置,并使用sass,css和样式加载器来编译我的项目中的sass.一切正常但我无法理解为什么当我运行时我webpack -p在我的包中得到一些样式加载器函数:

在此输入图像描述

正如您所见,节点模块由于某种原因包含在内,基本上包括style-loader和css-loader.这是正常的吗?这些功能有目的吗?

小智 0

我相信这是因为样式加载器本身被声明不在生产中使用。

"For production builds it's recommended to extract the CSS from your bundle being able to use parallel loading of CSS/JS resources later on. This can be achieved by using the mini-css-extract-plugin, because it creates separate css files. For development mode (including webpack-dev-server) you can use style-loader, because it injects CSS into the DOM using multiple and works faster."

https://webpack.js.org/loaders/style-loader/

I would check your webpack config for development and production, likely the rule for the using style-loader is not present.