ciaoben
ciaoben

Reputation: 3338

Why is style-loader included in my production bundle?

I have a minimal webpack setup and using sass, css and style loaders to compile sass in my project. Everything works fine but I can't understand why when I run webpack -p I get some style-loader functions in my bundle:

enter image description here

As you can see node-modules are included for some reason, basically to include style-loader and css-loader. Is it normal? Do these functions have a purpose ?

Upvotes: 7

Views: 553

Answers (1)

Richard Sanna
Richard Sanna

Reputation: 11

I believe it's because style-loader itself is declared not to be used in production.

"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.

Upvotes: 0

Related Questions