Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
style-loader
Advanced tools
The style-loader npm package is used to inject CSS into the DOM using multiple strategies. It is often used in combination with css-loader in webpack configurations to handle styles within JavaScript modules.
Inject styles into the DOM
This code sample demonstrates how to use style-loader in combination with css-loader to import a CSS file and inject the styles into the DOM.
import style from 'style-loader!css-loader!./style.css';
Useable styles
This code sample shows how to use the useable feature of style-loader to manually control when styles are injected into and removed from the DOM.
import style from 'style-loader/useable!css-loader!./style.css';
style.use(); // Injects styles
tyle.unuse(); // Removes styles
Lazy loading styles
This code sample illustrates how to lazy load styles with style-loader, which can be useful for code splitting scenarios.
import loadStyle from 'style-loader!css-loader!./style.css';
loadStyle().then(style => {
// Use style here
});
css-loader interprets @import and url() like import/require() and will resolve them. It is often used alongside style-loader in webpack configurations.
This webpack plugin extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. It is useful for caching and parallel loading but does not inject styles into the DOM like style-loader.
sass-loader compiles Sass/SCSS files to CSS. It is used in combination with css-loader and style-loader in webpack configurations to handle styles written in Sass/SCSS.
require("style!raw!./file.css");
// => add rules in file.css to document
It's recommended to combine it with the css-loader
: require("style!css!./file.css")
.
It also possible to add a URL instead of a css string:
require("style/url!file!./file.css");
// => add a <link rel="stlyesheet"> to file.css to document
var style = require("style/useable!css!./file.css");
style.use(); // = style.ref();
style.unuse(); // = style.unref();
Styles are not added on require, but instead on call to use
/ref
. Styles are removed from page if unuse
/unref
is called exactly as often as use
/ref
.
Note: Behavior is undefined when unuse
/unref
is called more often than use
/ref
. Don't do that.
By convention the reference-counted API should be bound to .useable.css
and the simple API to .css
(similar to other file types, i. e. .useable.less
and .less
).
So the recommended configuration for webpack is:
{
module: {
loaders: [
{ test: /\.css$/, exclude: /\.useable\.css$/, loader: "style!css" },
{ test: /\.useable\.css$/, loader: "style/useable!css" }
]
}
}
FAQs
style loader module for webpack
The npm package style-loader receives a total of 2,793,953 weekly downloads. As such, style-loader popularity was classified as popular.
We found that style-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.