survivejs / webpack-book

From apprentice to master (CC BY-NC-ND)
https://survivejs.com/webpack/
2.42k stars 319 forks source link

Is bundling style via webpack a good practice? #22

Closed vincenzo-antolini-os closed 9 years ago

vincenzo-antolini-os commented 9 years ago

Hi, I read this page: https://christianalfoni.github.io/react-webpack-cookbook/Loading-CSS.html I made some tests, a virtual css style-sheet was appended to <head> via javascript. I tested style-loader, css-loader and less-loader chaining style!css!less and it worked as expected.

Wow... But I have a lot of questions flying in my head... I really dunno if I want to do this... If not out of scope, can you add some thoughts about embedding css this way?

Thanks V

bebraw commented 9 years ago

See how Ben Smithett does it. I hope that helps.

@christianalfoni Any thoughts?

christianalfoni commented 9 years ago

Hi,

I definitely think you should embed styles this way :-)

What Webpack does is removing the "thinking different types of assets". Everything is just a "chunk" you need to load into your project. It being, css, javascript, fonts or an image. So the question is not as much "how to load", but "when to load".

This is where lazy loading and "css by component" comes into play. It depends heavily on the project what strategy works for you, but handling CSS just like you handle JS is a great concept I think.

Very abstract thoughts this, but please tell us a bit about your project and we can come up with some specific suggestions?

vincenzo-antolini-os commented 9 years ago

:+1: thanks for your opinion... It's too early for suggestions, I have too much informations swirling in my head. My mantra after starting ReactJs and WebPack: "Stay alert! don't overengineering! Be critic!"

I like the concept "you decide when to load an asset" but just now seems to be an abstraction that has no place in real world.

Thanks V