Skip to content
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

Merged
merged 6 commits into from
Apr 30, 2017
Merged

Conversation

ilanc
Copy link
Contributor

@ilanc ilanc commented Jan 13, 2017

…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

@jsf-clabot
Copy link

jsf-clabot commented Jan 13, 2017

CLA assistant check
All committers have signed the CLA.

@SpaceK33z SpaceK33z changed the title add option.cssBase = workaround for https://github.com/webpack/style-… add option.cssBase = workaround for #163 Jan 13, 2017
@zojeda
Copy link

zojeda commented Jan 17, 2017

+1 we are having the same issue, this worked fine for us, hope this PR gets approved

@michael-ciniawsky
Copy link
Member

@ilanc Please close and reopen the PR to trigger the CLA Bot again and signed the CLA please 😛

@michael-ciniawsky
Copy link
Member

Also add a test please

@ilanc
Copy link
Contributor Author

ilanc commented Mar 16, 2017

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

Copy link
Member

@ekulabuhov ekulabuhov left a 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.

@ekulabuhov
Copy link
Member

@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.

@michael-ciniawsky michael-ciniawsky removed their assignment Mar 16, 2017
@ilanc
Copy link
Contributor Author

ilanc commented Mar 18, 2017

Thanks @ekulabuhov I've just gone on holiday I'll look into it in 10 days time

@ilanc
Copy link
Contributor Author

ilanc commented Apr 3, 2017

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?

@bebraw
Copy link
Contributor

bebraw commented Apr 3, 2017

@ilanc Please rebase. A lot has been going on. 😄

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Apr 25, 2017

@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? 🙃

@alexander-akait
Copy link
Member

@michael-ciniawsky i have pure knowledge about Dll 😄 /cc @ilanc i am right that https://github.com/ilanc/style-loader-bug repo contain example bug?

@ilanc
Copy link
Contributor Author

ilanc commented Apr 25, 2017

@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.

@michael-ciniawsky
Copy link
Member

cssBase doesn't introduce any possible side effects for other users when not using/setting it right (I need to ask so naively 🙃 )? If so and it works with DllPlugin in a sample project, we could leave the test(s) for it in style-loader out, if impossible to unit test atm. Although I intend to run tests through webpack in the near future, but that's not a concern of yours, since it isn't in place yet 😛

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));
Copy link
Member

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' } ]`
Copy link
Member

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'
  ]
}

@michael-ciniawsky
Copy link
Member

@ilanc Could we use e.g options.cssBase * 1e3 to make the options terser

- { loader: 'style-loader`, options: { cssBase: 1000 } }
+ { loader: 'style-loader`, options: { cssBase: 1 } }

Naming

cssBase => base
cssBase => idBase

The intention to bump the module id range by e.g n * 1e3 when using DllPlugin isn't fully clear imho :)

@ilanc
Copy link
Contributor Author

ilanc commented Apr 27, 2017

I don't think options.cssBase * 1e3 makes any meaningful difference - i arbitrarily choose 1000. If you only require 5 css files in Dll1 then Dll2 probably only needs a cssBase of 6* or higher in order to avoid clashing with Dll1's css modules.

I prefer cssBase over the other suggestions because it's a css specific problem - the others are a bit generic.

* 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.

@michael-ciniawsky
Copy link
Member

I don't think options.cssBase * 1e3 makes any meaningful difference - i arbitrarily choose 1000. If you only require 5 css files in Dll1 then Dll2 probably only needs a cssBase of 6* or higher in order to avoid clashing with Dll1's css modules.

👍

I prefer cssBase over the other suggestions because it's a css specific problem - the others are a bit generic.

Disagreeing here since the css prefix doesn't add any meaning imho (nothing else then CSS is 'processed' by this loader anyways), so we can keep it terse and generic. Please rename to either id || base || range with base as the favorite, but enterily free choice between those three options and good to fo then 😛

@michael-ciniawsky
Copy link
Member

Please also close and reopen the PR to trigger the CLA Bot again and sign the CLA

@michael-ciniawsky michael-ciniawsky changed the title feat: add option.cssBase feat: add option.base Apr 28, 2017
@ilanc ilanc closed this Apr 30, 2017
@ilanc ilanc reopened this Apr 30, 2017
@ilanc
Copy link
Contributor Author

ilanc commented Apr 30, 2017

@michael-ciniawsky cool I think it's ready to go - looks like the CLA bot did it's thing.

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilanc Thx

@michael-ciniawsky michael-ciniawsky merged commit e4ac886 into webpack-contrib:master Apr 30, 2017
michael-ciniawsky added a commit that referenced this pull request Apr 30, 2017
@ilanc
Copy link
Contributor Author

ilanc commented Apr 30, 2017

:) happy to help

@michael-ciniawsky michael-ciniawsky modified the milestone: 0.18.0 May 8, 2017
@michael-ciniawsky michael-ciniawsky removed this from Feature in Dashboard May 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants