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

fix(getLocalIdent): add rootContext support (webpack >= v4.0.0) #681

Merged
merged 2 commits into from Feb 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/getLocalIdent.js
Expand Up @@ -6,8 +6,15 @@ var loaderUtils = require("loader-utils");
var path = require("path");

module.exports = function getLocalIdent(loaderContext, localIdentName, localName, options) {
if(!options.context)
options.context = loaderContext.options && typeof loaderContext.options.context === "string" ? loaderContext.options.context : loaderContext.context;
if(!options.context) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we solve this in one line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could refactor it to nested ternary expressions:
options.context = options.context || (loaderContext.rootContext ? loaderContext.rootContext : loaderContext.options && typeof loaderContext.options.context === "string" ? loaderContext.options.context : loaderContext.context)

Copy link
Member

Choose a reason for hiding this comment

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

@yavorsky it is better in future to maintenance, just add or remove new options/context and etc

Copy link
Contributor Author

@yavorsky yavorsky Feb 22, 2018

Choose a reason for hiding this comment

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

But we could just remove condition case.
Nested ternary expressions are not allowed by current eslint config (and my conscience :) ).

Copy link
Member

Choose a reason for hiding this comment

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

let's wait @michael-ciniawsky

Good work! Thanks!

if (loaderContext.rootContext) {
options.context = loaderContext.rootContext;
} else if (loaderContext.options && typeof loaderContext.options.context === "string") {
options.context = loaderContext.options.context;
} else {
options.context = loaderContext.context;
}
}
var request = path.relative(options.context, loaderContext.resourcePath);
options.content = options.hashPrefix + request + "+" + localName;
localIdentName = localIdentName.replace(/\[local\]/gi, localName);
Expand Down