Socket
Socket
Sign inDemoInstall

style-loader

Package Overview
Dependencies
Maintainers
6
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

style-loader - npm Package Compare versions

Comparing version 0.15.0 to 0.16.0

7

addStyles.js

@@ -14,3 +14,8 @@ /*

isOldIE = memoize(function() {
return /msie [6-9]\b/.test(self.navigator.userAgent.toLowerCase());
// Test for IE <= 9 as proposed by Browserhacks
// @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805
// Tests for existence of standard globals is to allow style-loader
// to operate correctly into non-standard environments
// @see https://github.com/webpack-contrib/style-loader/issues/177
return window && document && document.all && !window.atob;
}),

@@ -17,0 +22,0 @@ getElement = (function(fn) {

@@ -5,6 +5,17 @@ /*

*/
module.exports = function addStyleUrl(cssUrl) {
function attachTagAttrs(element, attrs) {
Object.keys(attrs).forEach(function (key) {
element.setAttribute(key, attrs[key]);
});
}
module.exports = function addStyleUrl(cssUrl, options) {
if(typeof DEBUG !== "undefined" && DEBUG) {
if(typeof document !== "object") throw new Error("The style-loader cannot be used in a non-browser environment");
}
options = options || {};
options.attrs = typeof options.attrs === "object" ? options.attrs : {};
var styleElement = document.createElement("link");

@@ -14,2 +25,5 @@ styleElement.rel = "stylesheet";

styleElement.href = cssUrl;
attachTagAttrs(styleElement, options.attrs);
var head = document.getElementsByTagName("head")[0];

@@ -16,0 +30,0 @@ head.appendChild(styleElement);

@@ -5,2 +5,17 @@ # Change Log

<a name="0.16.0"></a>
# [0.16.0](https://github.com/webpack/style-loader/compare/v0.15.0...v0.16.0) (2017-03-22)
### Bug Fixes
* **addStyles:** update for test for old IE versions ([#196](https://github.com/webpack/style-loader/issues/196)) ([1f68495](https://github.com/webpack/style-loader/commit/1f68495))
### Features
* Set custom attributes for tag in url mode ([#198](https://github.com/webpack/style-loader/issues/198)) ([2c4f427](https://github.com/webpack/style-loader/commit/2c4f427))
<a name="0.15.0"></a>

@@ -7,0 +22,0 @@ # [0.15.0](https://github.com/webpack/style-loader/compare/v0.14.1...v0.15.0) (2017-03-21)

2

package.json
{
"name": "style-loader",
"version": "0.15.0",
"version": "0.16.0",
"author": "Tobias Koppers @sokra",

@@ -5,0 +5,0 @@ "description": "style loader module for webpack",

@@ -87,7 +87,13 @@ [![npm][npm]][npm-url]

```javascript
require('style-loader?{attrs:{id: "style-tag-id"}}!style.scss');
require('style-loader?{attrs:{id: "style-tag-id"}}!style.css');
// will create style tag <style id="style-tag-id">
```
Usage in `url` mode:
```javascript
require('style-loader/url?{attrs:{prop: "value"}}!file-loader!style.css')
// will create link tag <link rel="stylesheet" type="text/css" href="[path]/style.css" prop="value">
```
### Recommended configuration

@@ -94,0 +100,0 @@

@@ -158,2 +158,25 @@ // Node v4 requires "use strict" to allow block scoped let & const

it("url with attrs", function (done) {
cssRule.use = [
{
loader: "style-loader/url",
options: {
attrs: {
'data-attr-1': 'attr-value-1',
'data-attr-2': 'attr-value-2'
}
}
},
"file-loader"
];
// Run
let expected = [
existingStyle,
'<link rel="stylesheet" type="text/css" href="ec9d4f4f24028c3d51bf1e7728e632ff.css" data-attr-1="attr-value-1" data-attr-2="attr-value-2">'
].join("\n");
runCompilerTest(expected, done);
}); // it url with attrs
it("useable", function(done) {

@@ -160,0 +183,0 @@ cssRule.use = [

@@ -10,2 +10,3 @@ /*

this.cacheable && this.cacheable();
var query = loaderUtils.getOptions(this) || {};
return [

@@ -15,3 +16,3 @@ "// style-loader: Adds some reference to a css file to the DOM by adding a <link> tag",

"\trequire(" + loaderUtils.stringifyRequest(this, "!!" + remainingRequest) + ")",
");",
", " + JSON.stringify(query) + ");",
"// Hot Module Replacement",

@@ -18,0 +19,0 @@ "if(module.hot) {",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc