Skip to content

Add a warning note for common errors when specifying rules #2376

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

Merged
merged 6 commits into from
Dec 16, 2018

Conversation

yaaminu
Copy link
Contributor

@yaaminu yaaminu commented Jul 22, 2018

When specifying a test in module.rules, webpack accepts either a regex or string. However it's easy to mistakenly qoute the regex which will cause webpack to not use the specified loader. I added this warning to help newcomers like me who might stumbled into this situation save themselves frustrations and wasted time.

When specifying a test in `module.rules`, webpack accepts either a regex or string. However it's easy to mistakenly qoute the regex which will cause webpack to not use the specified loader. I added this warning to help newcomers like me who might  stumbled into this situation save themselves frustrations and wasted time.
@jsf-clabot
Copy link

jsf-clabot commented Jul 22, 2018

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@montogeek montogeek left a comment

Choose a reason for hiding this comment

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

Just a typo

@@ -114,6 +114,8 @@ The configuration above has defined a `rules` property for a single module with

W> It is important to remember that when defining rules in your webpack config, you are defining them under `module.rules` and not `rules`. For your benefit, webpack will warn you if this is done incorrectly.

W> Keep in mind that when using regex to match files, you may not qoute it. i.e `\/.txt$/` is not the same as `'\/.txt$'`/ `"/\.txt$/"`. The former instructs webpack to match any file that ends with .txt and the later instructs webpack to match a single file with an absolute path '.txt'; this is likely not your intention.
Copy link
Member

Choose a reason for hiding this comment

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

quote

Copy link

Choose a reason for hiding this comment

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

did you mean /\.txt$/ instead of \/.txt$/?

Copy link

Choose a reason for hiding this comment

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

and I don't think any of you string variations will match anything at all, so I would omit the part about '.txt'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asapach you're right

@yaaminu
Copy link
Contributor Author

yaaminu commented Aug 10, 2018

@montogeek, typos fixed thanks

@@ -114,6 +114,8 @@ The configuration above has defined a `rules` property for a single module with

W> It is important to remember that when defining rules in your webpack config, you are defining them under `module.rules` and not `rules`. For your benefit, webpack will warn you if this is done incorrectly.

W> Keep in mind that when using regex to match files, you may not quote it. i.e `/\.txt$/` is not the same as `'/\.txt$/'`/ `"/\.txt$/"`. The former instructs webpack to match any file that ends with .txt and the later instructs webpack to match a single file with an absolute path '.txt'; this is likely not your intention.
Copy link
Member

Choose a reason for hiding this comment

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

on one hand this is regex knowledge related warning, on the other it may be useful to users. i am not voting for this and also not against it. If you are good with this pls merge @montogeek

@montogeek montogeek merged commit db50ffb into webpack:master Dec 16, 2018
@montogeek
Copy link
Member

Thanks!

EugeneHlushko added a commit that referenced this pull request Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants