style-loader icon indicating copy to clipboard operation
style-loader copied to clipboard

What does this loader do?

Open mimamuh opened this issue 10 years ago • 7 comments

There is a simple explanation missing what this loader is for and what it does. Just two sentences would be awesome! Thx.

mimamuh avatar Apr 20 '16 14:04 mimamuh

@MiMaMuh The first two code blocks in the README are commented with a description of what the code does:

require("style!raw!./file.css");
// add rules in file.css to document

In this case, the contents of ./file.css will be added to the document.

meyer avatar Apr 22 '16 01:04 meyer

Still have no idea about what this loader is about ? How does it work ? Where does it load css rules etc. It would be great to hear a clear explanation.

furkanedu avatar Apr 24 '16 18:04 furkanedu

It loads all the rules from your css files inside the <head> tag with the proper <style> tag

luisrudge avatar Apr 25 '16 02:04 luisrudge

What they mean is that it "inlines" the styles like <style> all my styles embedded here </style> - so they are not external but in the <head> of the document. It does have an option to load external styles by adding style/url to the loader

From readme:

require("style/url!file!./file.css"); // => add a <link rel="stylesheet"> to file.css to document

IAMtheIAM avatar May 17 '16 21:05 IAMtheIAM

@luisrudge @MiMaMuh If you don’t understand how style-loader works or where it loads styles, you should probably read more about webpack before tackling specific loaders.

Have you got webpack running in your project already? If not, please do that before asking how a loader works. Once you wrap your head around the basics of webpack, style-loader (and every other loader) will make sense.

If you’re unsure where to begin, there are dozens (probably hundreds by now) of boilerplate projects that you can get running quite easily. I recommend very minimal boilerplate projects (webpack config + a few files).

webpack-howto by Pete Hunt is a good place to start: https://github.com/petehunt/webpack-howto

meyer avatar May 22 '16 00:05 meyer

thanks @meyer .

furkanedu avatar May 23 '16 06:05 furkanedu

Dupe of #70. Note that we're working on adding better description in readme's for loaders soon.

SpaceK33z avatar Oct 29 '16 10:10 SpaceK33z