Skip to content

Conversation

@hybrist
Copy link
Contributor

@hybrist hybrist commented Mar 1, 2018

We want to match some of our existing asset logic which generates image file names from the source paths. Having a function that generates those paths seemed like the simplest solution.

This mirrors the way the file-loader works, allowing to reuse logic. https://github.com/webpack-contrib/file-loader#regexp

@jsf-clabot
Copy link

jsf-clabot commented Mar 1, 2018

CLA assistant check
All committers have signed the CLA.

@hybrist
Copy link
Contributor Author

hybrist commented Mar 1, 2018

Actually, trying to make sure that templates are supported in the returned value.

@hybrist hybrist changed the title Add support for toType "function" Add support for regex matches in to templates Mar 1, 2018
@michael-ciniawsky michael-ciniawsky changed the title Add support for regex matches in to templates feat(processPattern): add support for {RegExp) matches (patterns.toRegExp) Mar 1, 2018
@michael-ciniawsky michael-ciniawsky added this to the 4.5.0 milestone Mar 1, 2018
@michael-ciniawsky michael-ciniawsky changed the title feat(processPattern): add support for {RegExp) matches (patterns.toRegExp) feat(processPattern): add support for {RegExp) matches (pattern.toRegExp) Mar 1, 2018
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.

I'm in favor renaming pattern.toRegExp => pattern.test instead

README.md Outdated
from: 'src/'
to: 'dest/[name].[hash].[ext]',
toType: 'template'
// Optional: provide a regExp to extract additional placeholders
Copy link
Member

Choose a reason for hiding this comment

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

Please make a new 'section' for this option, or does it only work with toType: 'template' ?

Copy link
Member

@michael-ciniawsky michael-ciniawsky Mar 1, 2018

Choose a reason for hiding this comment

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

Also needs to be added to options table please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will only work with the template toType. Will update the table.

@michael-ciniawsky michael-ciniawsky changed the title feat(processPattern): add support for {RegExp) matches (pattern.toRegExp) feat(processPattern): add support for {RegExp) matches (pattern.test) Mar 1, 2018
@hybrist
Copy link
Contributor Author

hybrist commented Mar 1, 2018

Would it make sense to use pattern.regExp instead of pattern.test? That's consistent with how file-loader exposes this feature. Happy to switch to either. :)

@hybrist
Copy link
Contributor Author

hybrist commented Mar 1, 2018

  • Added to options table
  • Renamed to options.test
  • Added dedicated section for options.test to the README containing the same docs that also appear in the file-loader README for options.regExp

@alexander-akait
Copy link
Member

@jkrems rebase 👍

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.

👍

@hybrist
Copy link
Contributor Author

hybrist commented Mar 1, 2018

Rebase'd.

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.

Only minor important nitpicks, please rebase :)

README.md Outdated

### `test`

Defines a regExp to match some parts of the file path.
Copy link
Member

Choose a reason for hiding this comment

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

regExp => {RegExp}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

README.md Outdated

Defines a regExp to match some parts of the file path.
These capture groups can be reused in the name property using `[N]` placeholder.
Note that `[0]` will be replaced by the entire tested string,
Copy link
Member

Choose a reason for hiding this comment

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


> ℹ️ Note

string => {String}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went with "entire relative path of the file" while I was touching it since that seemed easier to understand than what the "tested string" was.

README.md Outdated
Defines a regExp to match some parts of the file path.
These capture groups can be reused in the name property using `[N]` placeholder.
Note that `[0]` will be replaced by the entire tested string,
whereas `[1]` will contain the first capturing parenthesis of your regex
Copy link
Member

Choose a reason for hiding this comment

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

regex => {RegExp}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@hybrist
Copy link
Contributor Author

hybrist commented Mar 2, 2018

Alright, the arguments to the interpolate call changed (relative -> absolute). Updated the test and docs to match that.

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.

@jkrems Thx

@michael-ciniawsky michael-ciniawsky merged commit 1861730 into webpack:master Mar 2, 2018
@michael-ciniawsky
Copy link
Member

Released in v4.5.0 🎉

@hybrist
Copy link
Contributor Author

hybrist commented Mar 2, 2018

Niiice! That was fast! Thanks a lot for the quick review & release. :)

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.

4 participants