Skip to content

Inherit getLocalIdent from parent loader #583

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

Closed
wants to merge 1 commit into from

Conversation

odensc
Copy link

@odensc odensc commented Jul 23, 2017

What kind of change does this PR introduce?
Bug fix.

Did you add tests for your changes?
No. (I couldn't figure out how to compose from a css file with the test helpers)

Summary
Someone using one of my libraries ran into an issue where getLocalIdent was not being applied to composed classes. (odensc/css-loader-minify-class#1)

Looking into the source code for css-loader, I found that the loader query is stringified sometimes - which causes it to lose the function reference to getLocalIdent. This PR fixes that by inheriting the getLocalIdent function from the parent loader if possible.

Also fixes #524 which was reported on this repo.

Does this PR introduce a breaking change?
No.

@jsf-clabot
Copy link

jsf-clabot commented Jul 23, 2017

CLA assistant check
All committers have signed the CLA.

@odensc
Copy link
Author

odensc commented Jul 23, 2017

(not sure what's wrong with AppVeyor)

@codecov
Copy link

codecov bot commented Jul 23, 2017

Codecov Report

Merging #583 into master will decrease coverage by 1.31%.
The diff coverage is 16.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #583      +/-   ##
==========================================
- Coverage   98.63%   97.31%   -1.32%     
==========================================
  Files          10       10              
  Lines         367      373       +6     
  Branches       87       89       +2     
==========================================
+ Hits          362      363       +1     
- Misses          5       10       +5
Impacted Files Coverage Δ
lib/loader.js 93.97% <16.66%> (-6.03%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eadbd47...de2ee8f. Read the comment docs.

@codecov
Copy link

codecov bot commented Jul 23, 2017

Codecov Report

Merging #583 into master will decrease coverage by 1.31%.
The diff coverage is 16.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #583      +/-   ##
==========================================
- Coverage   98.63%   97.31%   -1.32%     
==========================================
  Files          10       10              
  Lines         367      373       +6     
  Branches       87       89       +2     
==========================================
+ Hits          362      363       +1     
- Misses          5       10       +5
Impacted Files Coverage Δ
lib/loader.js 93.97% <16.66%> (-6.03%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eadbd47...de2ee8f. Read the comment docs.

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Jul 24, 2017

Could you try with

webpack.config.js

{
  loader: 'css-loader'
  options: {
    ident: 'css', // <= this line, which value isn't important
    getLocalIdent: () => {}
  }
}

This should prevent losing the reference to {Function} when options get stringified. Normally webpack >= v2.2.1 should add the ident automatically per default, but since >= 2.6.0 this seems to be buggy again 😞 . I had countless issues with that in postcss-loader

In case it doesn't work this._module is a deprecated Loader API ⚠️ , so the current fix won't work this way

@odensc
Copy link
Author

odensc commented Jul 24, 2017 via email

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.

getLocalIdent doesn't apply for composed classes
3 participants