-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Use Rule.oneOf to resolve correct loader #2747
Conversation
This is sooo sweet. Thank you. |
Thank @sokra as he pointed me in the right direction :D Yeah now I see I missed the dev config. Will add that in a bit. |
Did you figure this part out? |
Not yet. I can try my luck tomorrow but there is a chance I will come to no conclusion. Debugging webpack is a pain and But -- I added |
Let's hang on until you try to figure it out. If you can't, no sweat, just write here and we'll get somebody familiar with webpack internals to look at it. I'd like to understand better before merging. Thank you! |
Ok, I found out what the problem is and have two possible fixes for you. The culprit is the As a proof-of-concept I tried to patch the So here are my proposed solutions:
I'm happy to implement either one of these based on feedback. |
This sounds good to me. |
Should be good now. Thanks for your precious weekend time guiding me through this. If there is anything else I missed then feel free pointing me to it. |
@EnoahNetzach Let me know if you have any comments here! |
I’ll get this in for now. Thank you again! |
* Use oneOf to resolve correct loader * Add html and json fallthrough again * Use oneOf to resolve correct loader in dev * Document file-loaders `js` exclusion * Remove `jsx` from exclusion in prod config
// it's runtime that would otherwise processed through "file" loader. | ||
// Also exclude `html` and `json` extensions so they get processed | ||
// by webpacks internal loaders. | ||
exclude: [/\.js$/, /\.html$/, /\.json$/], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the exclude you could also add a empty rule matching these types
{
test: [/\.js$/, /\.html$/, /\.json$/]
// Don't use a loader for these types.
}
This would keep the file-loader rule focused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh. Nice! Thanks for that hint. Will create a PR to change this in time. Seems much cleaner.
* Use oneOf to resolve correct loader * Add html and json fallthrough again * Use oneOf to resolve correct loader in dev * Document file-loaders `js` exclusion * Remove `jsx` from exclusion in prod config
* Use oneOf to resolve correct loader * Add html and json fallthrough again * Use oneOf to resolve correct loader in dev * Document file-loaders `js` exclusion * Remove `jsx` from exclusion in prod config
* Use oneOf to resolve correct loader * Add html and json fallthrough again * Use oneOf to resolve correct loader in dev * Document file-loaders `js` exclusion * Remove `jsx` from exclusion in prod config
* Use oneOf to resolve correct loader * Add html and json fallthrough again * Use oneOf to resolve correct loader in dev * Document file-loaders `js` exclusion * Remove `jsx` from exclusion in prod config
* Use oneOf to resolve correct loader * Add html and json fallthrough again * Use oneOf to resolve correct loader in dev * Document file-loaders `js` exclusion * Remove `jsx` from exclusion in prod config
This PR uses the oneOf rule to resolve loaders in
webpack.config.prod.js
. This will use the first loader that matches in the list of loaders provided byoneOf
and enables us to remove the big exclusion list of thefile-loader
. The file loader will only be used if the module falls through all other loaders.https://webpack.js.org/configuration/module/#rule-oneof
For some reason though I had to still preserve the
js(x)
exclusion in the file loader. Otherwise the build would break. This happens with or without theeslint
preloader. Will have to investigate further why exactly this happens and why these unknownjs(x)
modules fall through to thefile-loader
.The
resolve
now looks something like this (pseudocode):