0

When using Webpack, it makes complete sense to use it to package your client-side JS. But what is the purpose of using it to compile your SASS and load your CSS into your page? In the end it appears that you need to use another Webpack plugin (ExtractTextWebpackPlugin) in order to pull out the CSS when you are ready to deploy to production.

It seems like you are going full circle here. Before Webpack you load your CSS in the <head> using a <link> tag like normal. Now using Webpack you load it via your JS bundle. And now for production you use a Webpack plugin to put it right back into the <head> tag again. So what's the point?

There are already dozens of tools and methods for compiling your CSS and live-reloading it in the page without Webpack. What is the advantage of using Webpack for your SASS/LESS/CSS to begin with?

4
  • Ask this on Webmaster, maybe? No real code issue. Commented Mar 26, 2018 at 2:40
  • And you actually made me type. I have a keyboard shortcut set up for telling people "Welcome to stack overflow, here's how to ask", but you have 36k rep, so that won't work :) Commented Mar 26, 2018 at 2:42
  • one less file to load? Commented Mar 26, 2018 at 2:43
  • Sorry you are right I should have asked elsewhere. Not the right place. Commented Mar 26, 2018 at 3:03

1 Answer 1

1

tl;dr I don't think you are looking at Webpack in its' full capacity. If you are hung up on just working with CSS preprocessors than just stick with their stand alone compliers and move on.

Webpack only reads JavaScript, so that's where Loaders come into play. When you want to start working with other file types you'll need to configure loaders to pull out the specific code and have it run the necessary tasks. It's no different than Gulp's Pipelines or Grunt's Configuration blocks.

The point of loading CSS (or any preprocessor) into Webpack is because you want to have a full fledge task runner that handles bundling your code, live-reloading, image optimization, environment variables, code optimizations, HTML templates, among everything else that's possible. You wouldn't just use Webpack as a standalone CSS Preprocessor that's not the objective.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay but in the end your CSS needs to be pulled out of Webpack again for a production website. Seems kind of weird to put it in and then have to pull it out again. Why not just leave it out to begin with? Like what is the advantage here? I feel like I'm missing something.
Regardless of the environment Webpack can't natively support CSS or any preprocessor. I feel like you're hung up on making a reference with Webpack, Webpack then uses a loader for processing, and then puts the file back in place ready for production. Essentially there's no real advantage in this scenario (please correct if wrong). But, I've solely used Webpack for decent sized React applications so experiences may vary. Honestly I feel like you'd be better served using Gulp for your needs. It's fast, simple, and probably the quickest way to get up and running.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.