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

Allow function interpolation #59

Merged
merged 3 commits into from
Feb 15, 2017
Merged

Allow function interpolation #59

merged 3 commits into from
Feb 15, 2017

Conversation

KristofMorva
Copy link
Contributor

Currently generating names is quite restrictive - it only allows a fix number of opportunities.
I propose letting the name parameter to be a function, so developers can return whatever name they want based on the resource path with their own logic.
As a real-life example, I would like assets in node_modules to be in a subfolder of images named after the package, while assets from other paths should be placed in the root of images. Currently I haven't found a way to achieve this.

There should be no breaking change to existing configurations.

@jsf-clabot
Copy link

jsf-clabot commented Feb 13, 2017

CLA assistant check
All committers have signed the CLA.

@jhnns
Copy link
Member

jhnns commented Feb 13, 2017

That looks good, thank you.

Could you replace the instanceof check with typeof? Checking functions this way is pretty uncommon. Please also remove the newline on 258 to match the coding style.

@KristofMorva
Copy link
Contributor Author

Sure @jhnns, I have changed it as requested.

index.js Outdated
@@ -249,7 +249,12 @@ exports.getHashDigest = function getHashDigest(buffer, hashType, digestType, max
};

exports.interpolateName = function interpolateName(loaderContext, name, options) {
var filename = name || "[hash].[ext]";
var filename;
if (typeof name === 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for nitpicking, but please use double quotes 😁 (you can push force on this branch)

Copy link
Contributor Author

@KristofMorva KristofMorva left a comment

Choose a reason for hiding this comment

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

@jhnns I have used triple equations, because that was used everywhere else in the script, but I have changed as requested.

@jhnns
Copy link
Member

jhnns commented Feb 15, 2017

Sorry, that's a misunderstanding. Triple-equality === was ok, please re-add that. I meant " for strings.

@jhnns
Copy link
Member

jhnns commented Feb 15, 2017

I'll change that with my next commit. Anyway, thx 👍

@jhnns jhnns merged commit c46f939 into webpack:master Feb 15, 2017
@KristofMorva
Copy link
Contributor Author

@jhnns haha sorry, I totally misinterpreted :)

@KristofMorva KristofMorva deleted the function-interpolation branch February 15, 2017 16:32
@jhnns
Copy link
Member

jhnns commented Feb 20, 2017

Shipped with 0.2.17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants