-
Notifications
You must be signed in to change notification settings - Fork 94
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 resolve block to prefer custom extensions over defaults #177
Fix resolve block to prefer custom extensions over defaults #177
Conversation
packages/core/lib/blockUtils.js
Outdated
@@ -1,5 +1,6 @@ | |||
const _ = require('lodash') | |||
const webpackMerge = require('webpack-merge') | |||
const webpackBlocksMerge = webpackMerge.smartStrategy({ 'resolve.extensions': 'prepend' }) |
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.
For now I left it inlined, but in case there will be more custom behavior I'd recommend moving this object to something like merge-strategies.js
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.
I would say we should rather put this into resolve().
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.
When putting it to resolve
, we start introducing a lot of small different merge behaviors.
webpack-blocks
allows you to define your own strategies and I think it makes sense to make use of it, as it alters only the object paths defined.
But yeah, we can still refactor this in case there are a lot of different merging strategies we want to have.
You could also argue as well that this isn't core behavior and some people might want to write something that actually replaces / appends / do other crazy stuff.
Going to change ✅
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.
We should put that logic into the resolve(). Putting the fix for resolve()
so far away from it, under the hood, feels like a foot gun 😉
packages/core/lib/blockUtils.js
Outdated
@@ -1,5 +1,6 @@ | |||
const _ = require('lodash') | |||
const webpackMerge = require('webpack-merge') | |||
const webpackBlocksMerge = webpackMerge.smartStrategy({ 'resolve.extensions': 'prepend' }) |
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.
I would say we should rather put this into resolve().
Thanks for your PR, @zcei! |
2415996
to
9a38a52
Compare
@andywer I exposed a new util fn, that allows merging with given strategy, to not duplicate the And it makes it very clear in every single block how you alter the default behavior. WDYT? |
I get your intention, but my personal aim is to keep the utils as slim as possible. As you might know there is already a long-running discussion if util functions should be passed to the blocks at all. Duplicating the webpack-merge dependency to After all: No one said you have to stick to the utils to do the merging. In fact the 1.0 API blackboxes the way a block applies its changes to the config, so if you need something special (like here), feel free to do whatever you need to do in the block :) |
Btw, sorry for the wall of text 😉 I would open a PR with my solution and let you review it as soon as I find a few minutes time, but I wanted to wait for your response/feedback or that of my fellow co-contributors first. |
Yes, I was actually looking into putting it into the Happy to review other approaches, but better not double the work 🙂 |
Sure, let's not double the work. Update the PR when you got time. But if you are just lacking the unit tests, don't mind; I would add them as well :) |
9a38a52
to
f023ecc
Compare
Sorry, was a bit short on time, but pushed what I got now, including a bare-minimal test to actually check the prepend behavior. |
Allow custom extensions configurations, like
so that
first checks
./foo.custom.js
before falling back to./foo.js
Closes #176