-
-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add option.base #164
Conversation
+1 we are having the same issue, this worked fine for us, hope this PR gets approved |
@ilanc Please close and reopen the PR to trigger the CLA Bot again and signed the CLA please 😛 |
Also add a test please |
Hi there @michael-ciniawsky I've re-signed the CLA. How do I add a test in this case? Did you see the related bug report btw? https://github.com/ilanc/style-loader-bug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an explanation of the new option to the README.
@ilanc a good unit test here would be to re-create the exact problem you had and show that your fix indeed solves it. Have you looked at the test/basicTest.js? They exercise webpack with different loader setups and configurations in memory. Tell me if you're having any problems setting it up. |
Thanks @ekulabuhov I've just gone on holiday I'll look into it in 10 days time |
Hi chaps, I've added the notes to the README. I don't have the tests in my branch - looks like these were added in Feb. Do you want me to merge (or perhaps rebase) my changes off the latest head? |
@ilanc Please rebase. A lot has been going on. 😄 |
@ilanc I will try to take a look at it, but I haven't much experience using the DllPlugin @bebraw @d3viant0ne @evilebottnawi anyone used to DllPlugin and cpuld help @ilanc with this? 🙃 |
@michael-ciniawsky i have pure knowledge about |
@michael-ciniawsky @bebraw @d3viant0ne @evilebottnawi Yes https://github.com/ilanc/style-loader-bug gives you a good example of DllPlugin in use. It's theoretical though - i.e. it's not a real app. See this article if you want to see a real use case. The style-loader-bug repo is a good minimal example for use as a unit test. However as I mentioned you're going to have to jump through a lot of hoops if you want to have a unit test in the style-loader project which depends on functionality in the core webpack repo (DllPlugin functionality lives in core webpack IIRC). CssBase is only useful with DllPlugins - there's no css clash between existingStyles and webpack css - I thought of trying this as a unit test but there's no clash so it's not a useful unit test for cssBase. The clash only occurs when you load a DllPlugin. Load up the style-loader-bug repo and follow the build instructions in the readme.md then run in chrome with dev tools open and single step through the code. There are comments in the .html file showing what's going wrong. |
|
addStyles.js
Outdated
var styles = []; | ||
var newStyles = {}; | ||
for(var i = 0; i < list.length; i++) { | ||
var item = list[i]; | ||
var id = item[0]; | ||
var id = item[0] + (+(options.cssBase || 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- var id = item[0] + (+(options.cssBase || 0))
+ var id = options.cssBase ? item[0] + options.cssBase : item[0]
README.md
Outdated
#### `cssBase` | ||
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. `cssBase` 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.: | ||
* webpack.dll1.config.js | ||
* `loaders:[ { test: /\.css$/, loader: 'style-loader!css-loader' } ]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use webpack 2 syntax here 😛
{
test: /\.css$/,
use: [
{ loader: 'style-loader', options: { cssBase: 1000 } },
'css-loader'
]
}
@ilanc Could we use e.g - { loader: 'style-loader`, options: { cssBase: 1000 } }
+ { loader: 'style-loader`, options: { cssBase: 1 } } Naming
The intention to bump the module id range by e.g |
I don't think I prefer * Of course the number of modules in a Dll plugin isn't exactly equal to the number of require statements so using 1000 is just being cautious. |
👍
Disagreeing here since the |
Please also close and reopen the PR to trigger the CLA Bot again and sign the CLA |
@michael-ciniawsky cool I think it's ready to go - looks like the CLA bot did it's thing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilanc Thx
This reverts commit e4ac886.
:) happy to help |
…loader/issues/163
What kind of change does this PR introduce?
bugfix / workaround for #163
Did you add tests for your changes?
no
If relevant, did you update the README?
no
Summary
This is a workaround. It allows the user to manually specify base id's for each bundle when multiple bundles are used on a page. The user would for have to manually specify the order in various webpack.configs like so:
dll1.js
loaders:[ { test: /\.css$/, loader: 'style-loader!css-loader' } ]
dll2.js
loaders:[ { test: /\.css$/, loader: 'style-loader?cssBase=1000!css-loader' } ]
app.js
loaders:[ { test: /\.css$/, loader: 'style-loader?cssBase=2000!css-loader' } ]
see #163
Does this PR introduce a breaking change?
no - the user has to opt in - there's no impact if the user doesn't specify
option.cssBase
Other information