-
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
webpack-merge or not? #34
Comments
Is webpack-merge doing anything special webpack related? If not that much, we could simply use lodash.merge. There is even a package for just that function called lodash.merge. It's what I was using for Webpacker and it is working pretty well. Instead of doing AFAIK merge.smart is doing the same thing + merging loaders if they have the same regex. Not sure it is much need and would probably be easy to replicate. |
@eXon Yeah, The problem about With the immutability helpers you could do this: |
I think we will need to normalize configs just like the entry point to make sure everything is merged correctly. There is no way around it. I've been using immutable.js for some time so I understand there is some benefits to this. |
I think using the immutability helpers would give us much more power and at the same time make the webpack config merging details more explicit. There are two ways I see right now: The soft wayHaving a simple heuristic to determine if a webpack config snippet is supposed to be handled by the immutability helper (by looking for Pro:
Contra:
The hard wayDropping webpack-merge and focusing on the immutability helper. Pro:
Contra:
|
I don't really like either. The hard way might be better because I don't think there is a lot of blocks written ATM and a minor version bump could do the job. However, I'm not sure if it's needed at all. After reading the code (didn't expected it to be that small), I'm not sure what are the problematic use-cases. The Care to give a few examples that are either problematic or anoying? |
I'm not a big fan of the "hard" way. It forces complexity on the user... which isn't the point of webpack-blocks to reduce it? The soft way is a solid compromise but I think it's overkill. Another option could be to add another webpack-block export that is called UPDATE: I noticed that webpack-merge v2.0 has merge.strategy (https://github.com/survivejs/webpack-merge#api) which allows the replacing of values. That could also work with a At the end of typing that, I'm trying to understand why someone would want to clear a previous webpack config anyway? I think that means that specific webpack-block doesn't fit your needs. |
The "hard way" would add a little more complexity, but just for the ones writing blocks, not for the ones using those blocks. So it's not that bad 😉 But it's not just about clearing properties, but also appending vs. prepending items to an array, for instance. This is quite important, since array config props are usually order-sensitive. Yes, there is |
This might also have an impact on #14. Dropping loaders from the config and adding a plugin instance that includes those loaders is not feasible with |
We're running into issues w/ the 2.0 extraction because of this. Specifically, extract-text-plugin previously relied on moving from a compound The approach that I took in Blocks takes a different appraoch though and goes for multiple blocks that compose (so you could have sass, postcss, less, extracttextplugin) all as separate blocks. This likely means some reliance upon merge.smart. Unfortunately, it breaks down. So, when it breaks down, it is nice to be able to fall back to an updater function. The function would take the entire webpack config and return the new webpack config. It wouldn't need to be an all-or-nothing approach, in webpack-parts I handled both returning objects from parts (which were merged) and functions (which were invoked). webpack-blocks complicates things a little further with its group functionality. I think that that entire functionality can be replaced by flattening the arguments to So that means createConfig can take arguments of 3 types: Arrays: flattened out I handled a fourth, falsey things, which were filtered out. This allowed me to write parts like: const hotModuleReloading = (
{
useReactHotLoader,
useWebpackHotMiddleware,
webpackDevServerUrl,
} = {}
) => ifProd(
null,
[
failIfNotConfigured('entry', 'hotModuleReloading'),
useWebpackHotMiddleware &&
prependToEachEntry('webpack-hot-middleware/client'),
webpackDevServerUrl && prependToEachEntry('webpack/hot/only-dev-server'),
webpackDevServerUrl &&
prependToEachEntry(`webpack-dev-server/client?${webpackDevServerUrl}`),
useReactHotLoader && prependToEachEntry('react-hot-loader/patch'),
{
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
],
}
]
) |
@aaronjensen Ohh yeah, that is an issue... You already have some good points, but I want to further clarify a few things:
Yeah, right now I see two alternatives to
The first approach could also allow a soft transition (we check if a block returns a config snippet or an update function), might be a good idea, but might also make things fuzzy... Gotta keep thinking about that. I also fear that 2. makes blocks harder to read. Upside is, though: It makes them easier to debug, since a list of immutability-helper objects is easy to serialize, a list of functions is usually not.
I don't think this is really part of this discussion, but just for clarification: We can speak about anything beyong that later. For now I would like to focus on the |
Is the fuzziness you're referring to the fact that a block has two modes of operation now? Function vs object? I'd think of the object as a shortcut/convenience mechanism, but you could do away w/ that by providing a
I'd strongly advise against this, you'd just be coupling to another tool that may have its limitations. I could see us having a similar discussion some days/weeks after starting down that path. I think it's better to allow the block creator to make the tool choice. Personally, I'd use updeep if I needed something like
If debugging is necessary, printing the before/after (input/output) as well as the function name would be a fine experience IMO. I don't think seeing the intermediate objects would be super necessary to debug. Functions are pretty easy to test and work with.
Sorry, I should have been more clear. I actually tried to implement allowing a function to be returned from a block and was stopped by the group functionality, which is why I brought it up. I agree though, we can work it out once the decision is made which way to go. |
Yeah. Having just one way to do it (functions only) seems cleaner, but having two might be more convenient, esp. if the function use-case is frequently not needed.
Fair enough. I am leaning towards the update function as well. Added a gist with a suggestion for a new API here: https://gist.github.com/andywer/4bdd9f4e5b3e6d4b94a1f4d843304dc4 |
Closing this issue, since 1.0 will allow the blocks to merge config as they like. |
Right now webpack-blocks is using webpack-merge to merge the blocks' config snippets to a complete config object.
There are some problems with webpack-merge, though:
The webpack-merge makers are already discussing the issue (survivejs/webpack-merge#45), but I am not a big fan of the proposed approach.
Possible solution: Use https://github.com/kolodny/immutability-helper instead of webpack-merge altogether.
Open for discussion :)
The text was updated successfully, but these errors were encountered: