You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: use inline styles even in sourcemap-enabled setups
Fixes broken relative and protocol-relative url() use in stylesheets when
source maps are enabled. Chrome >=57 and Firefox >=50.1 support loading source
maps when sourceMapURL directive is dynamically added to a new or existing style
element in the DOM. This means that style-loader can simply add the styles and
sourceMapURL directive as text inside a style element and the source map will be
loaded by the browser. Given the simpler insertion method, the relative and
protocol-relative urls in stylesheets will not break.
Copy file name to clipboardExpand all lines: README.md
+5-7Lines changed: 5 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,10 +73,6 @@ By default, the style-loader inserts the `<style>` elements into the `<head>` ta
73
73
74
74
If defined, the style-loader will re-use a single `<style>` element, instead of adding/removing individual elements for each required module. **Note:** this option is on by default in IE9, which has strict limitations on the number of style tags allowed on a page. You can enable or disable it with the singleton query parameter (`?singleton` or `?-singleton`).
75
75
76
-
#### `convertToAbsoluteUrls`
77
-
78
-
If convertToAbsoluteUrls and sourceMaps are both enabled, relative urls will be converted to absolute urls right before the css is injected into the page. This resolves [an issue](https://github.com/webpack/style-loader/pull/96) where relative resources fail to load when source maps are enabled. You can enable it with the convertToAbsoluteUrls query parameter (`?convertToAbsoluteUrls`).
79
-
80
76
#### `attrs`
81
77
82
78
If defined, style-loader will attach given attributes with their values on `<style>` / `<link>` element.
@@ -113,8 +109,11 @@ So the recommended configuration for webpack is:
113
109
{
114
110
test:/\.useable\.css$/,
115
111
use: [
116
-
{
117
-
loader:"style-loader/useable"
112
+
{
113
+
loader:"style-loader",
114
+
options: {
115
+
useable:true
116
+
},
118
117
},
119
118
{ loader:"css-loader" },
120
119
],
@@ -124,7 +123,6 @@ So the recommended configuration for webpack is:
124
123
}
125
124
```
126
125
127
-
**Note** about source maps support and assets referenced with `url`: when style loader is used with ?sourceMap option, the CSS modules will be generated as `Blob`s, so relative paths don't work (they would be relative to `chrome:blob` or `chrome:devtools`). In order for assets to maintain correct paths setting `output.publicPath` property of webpack configuration must be set, so that absolute paths are generated. Alternatively you can enable the `convertToAbsoluteUrls` option mentioned above.
0 commit comments