-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Extendable base config #884
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
Conversation
function removeOuterSlashes(string) { | ||
return string.replace(/^\/*/, '').replace(/\/*$/, '') | ||
} | ||
const removeOuterSlashes = string => |
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.
Do you prefer this syntax for any particular reason? Personally, I find it much harder to read. And =>
!= ES6 function. Their behavior is slightly different although it doesn't matter in this case.
To me, this is like changing:
class Environment {
constructor() {
...
}
}
to:
const Environment = class {
constructor() {
...
}
}
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.
Nope, just little less curly's {}
and parans ()
for one liner functions 😄
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.
Yeah, for some cases it doesn't do much though.
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.
Happy to change it back if you don't like it 😉 although at some places we have fat arrows so would be ideal to make it consistent in that sense
@gauravtiwari With this strategy, how would we modify one of the default plugins? For example, we need to modify the options for the |
@rossta The plugins are bit complicated since they don't share same API for defining options, which makes merging hard. So at the moment, one has to re-add that plugin with new options and it will override the previous plugin. I am investigating to see if it's possible to add similar API for plugins too. |
@gauravtiwari maybe store the loaders and plugins as an Array of Objects with a name and a value property. I experimented with something like that here, maybe it is actually a viable approach. This way, you can add plugins/loaders/other properties via an API, but still have a way to access the predefined rules or plugins webpack does using a name and not relying on webpacker to change the order of the items in the array. |
Thanks @WoH I haven't got chance to look at this again but will do at some point this week 👍 |
4091408
to
ead5716
Compare
2283f2d
to
bbf5abb
Compare
@gauravtiwari Thanks for sharing this work. I like that we can configure plugins now. One concern I had with the current |
Thanks for this @gauravtiwari Oops sorry. updated the question because I wrote the question wrongly. @gauravtiwari Which one will take precedence? |
@ytbryan The one set later, environment.loaders.set('json', jsonLoader, 'top') // now at 0th position in array i.e. head
environment.loaders.set('json', jsonLoader, 1) // now at 1st position in array
// [firstLoader, jsonLoader, ...moreLoaders] |
@rossta Yes, now the order can be controlled any way you like, not just inserting at the top or bottom but at any position in the list. |
Reading through your examples, I'm finding the 3rd positioning argument unclear. // Add json loader at top
environment.loaders.set('json', jsonLoader, 'top')
// Or 3rd in the list
environment.loaders.set('json', jsonLoader, 3) I'd prefer to see a new set of methods with descriptive names like: // Insert at the top
environment.loaders.prepend('json', jsonLoader)
// Insert at the bottom
environment.loaders.append('json', jsonLoader)
// Insert before/after an existing loader
environment.loaders.insert('json', jsonLoader, { before: 'typescript' })
environment.loaders.insert('json', jsonLoader, { after: 'typescript' }) wdyt? |
Yeah, I like it and had similar ideas earlier but didn't wanted to introduce a breaking change. Ahh I see, you mean extra set of methods apart from |
Yeah, |
bbf5abb
to
7408f61
Compare
4ff8e81
to
64e9094
Compare
64e9094
to
0b4bbca
Compare
@javan Updated the PR and description with new API changes (see examples in PR description) |
@ytbryan Could you please give this a try and see if it works as intended? |
d89f6c0
to
d73230e
Compare
* @class | ||
* @extends { Object } | ||
*/ | ||
class ConfigObject extends Object { |
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.
Extending native Object
(and Array
above) could have unexpected consequences. I don't have any references to point to, but it's generally not something I do. Do you have any thoughts? Alternatively, these could be bare classes that manage an object internally.
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.
Yeah, I read a bit about it but it seems for our use case it's safe to use since the usage is limited only to webpack config and unlike prototype
it doesn't change native objects.
I tried using bare classes with internal object but ran into some gotchas. We basically need native types with some custom methods on it.
Do you think it's bad for our use case?
It's worth restating what problems / issues these changes resolve in the PR description. There are a lot of nice API addditions here, but also a lot of changes and increase to the overall footprint. It might be nice to split this into two pull requests: one to resolve the issues, and a second to modernize and refactor (like your |
Yeah, makes sense. I will do this first and then modernisation later 👍 |
Remove toWebpackConfig() Expose entries Export all loaders Add webpack merge Revert toWebpackConfig() Add new API's for adding loader and plugins Fix loaders Move base plugins to config
Remove toWebpackConfig() Update API Cleanup More cleanup
Make loaders rules
d73230e
to
145a2d2
Compare
Going to merge this as is, looks good to me 👍 |
|
||
set(key, value) { | ||
return this.add({ key, value }) | ||
} |
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 think we should deprecate set
in favor of append
since append
/ prepend
have nice symmetry. For now, let's have set
call append
instead of the other way around.
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.
Sure, will make a PR
} | ||
|
||
append(key, value) { | ||
return this.set(key, value) |
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.
This should call add
directly instead of set
.
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.
👍
This PR exposes a base webpack config and a few new API's for updating loaders, plugins and configs so it can be extended from environment instead of separate environment files.
Issues this PR solves:
resolve.modules
through environment so it can be updated like loaders and plugins.1. List API
2. Object API
Examples
There are some other chores done here:
loader
touse
Fixes: #850 and #794
Closes: #836
Please review
cc // @molefrog @n0nick @renchap @rossta