Skip to content

Commit e4ac886

Browse files
Ilan Copelynmichael-ciniawsky
Ilan Copelyn
authored andcommitted
feat: add option.base (#164)
1 parent 6ca068f commit e4ac886

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,39 @@ require('style-loader/url?{attrs:{prop: "value"}}!file-loader!style.css')
9393
// will create link tag <link rel="stylesheet" type="text/css" href="[path]/style.css" prop="value">
9494
```
9595

96+
#### `base`
97+
This setting is primarily used as a workaround for [css clashes](https://github.com/webpack-contrib/style-loader/issues/163) when using one or more [DllPlugin](https://robertknight.github.io/posts/webpack-dll-plugins/)'s. `base` allows you to prevent either the *app*'s css (or *DllPlugin2*'s css) from overwriting *DllPlugin1*'s css by specifying a css module id base which is greater than the range used by *DllPlugin1* e.g.:
98+
* webpack.dll1.config.js
99+
```
100+
{
101+
test: /\.css$/,
102+
use: [
103+
'style-loader',
104+
'css-loader'
105+
]
106+
}
107+
```
108+
* webpack.dll2.config.js
109+
```
110+
{
111+
test: /\.css$/,
112+
use: [
113+
{ loader: 'style-loader', options: { base: 1000 } },
114+
'css-loader'
115+
]
116+
}
117+
```
118+
* webpack.app.config.js
119+
```
120+
{
121+
test: /\.css$/,
122+
use: [
123+
{ loader: 'style-loader', options: { base: 2000 } },
124+
'css-loader'
125+
]
126+
}
127+
```
128+
96129
### Recommended configuration
97130

98131
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`).

addStyles.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = function(list, options) {
5252
// By default, add <style> tags to the bottom of the target
5353
if (typeof options.insertAt === "undefined") options.insertAt = "bottom";
5454

55-
var styles = listToStyles(list);
55+
var styles = listToStyles(list, options);
5656
addStylesToDom(styles, options);
5757

5858
return function update(newList) {
@@ -64,7 +64,7 @@ module.exports = function(list, options) {
6464
mayRemove.push(domStyle);
6565
}
6666
if(newList) {
67-
var newStyles = listToStyles(newList);
67+
var newStyles = listToStyles(newList, options);
6868
addStylesToDom(newStyles, options);
6969
}
7070
for(var i = 0; i < mayRemove.length; i++) {
@@ -100,12 +100,12 @@ function addStylesToDom(styles, options) {
100100
}
101101
}
102102

103-
function listToStyles(list) {
103+
function listToStyles(list, options) {
104104
var styles = [];
105105
var newStyles = {};
106106
for(var i = 0; i < list.length; i++) {
107107
var item = list[i];
108-
var id = item[0];
108+
var id = options.base ? item[0] + options.base : item[0];
109109
var css = item[1];
110110
var media = item[2];
111111
var sourceMap = item[3];

0 commit comments

Comments
 (0)