-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Change webpack config options behavior in 5.0.0 #323
Comments
I agree on both points. 1st should act as close to webpack behavior as possible. Is there a chance to re-use this from webpack? Not sure they have this as a module but I believe that would be useful for many tools. 2nd: I think config lookup should be prevented only if |
They have agreed to accept a pull request with extraction this logic to a separate file (not package) but until we can drop webpack 1 support we’ll have to copypaste it.
In this case yes. You either specify a path or Styleguidist will try to use default location. So only |
I think the most streight forward way is to just let user always specify the webpackConfig, its also easy enough for the user to require it and pass it. This way you have just one option instead of 2 and you can always modify whatever you want before giving it to sg. |
We are optimizing here for the case where sg can work without any config right after install, right? Is it realistic anyways? |
The goal is to make it work with an existing webpack configuration. And to simplify initial configuration. To be able to run and show something useful with as little configuration as possible.
This make sense. Right now the only difference in merging behavior is that
Users don’t want to modify their already working configuration. Especially if they have no idea what they have to modify to make it work ;-)
With create-react-app — yes. |
I think we have 3 logics for configuring which aimed to make the whole thing easier but potentially introduce to many options and at the end make it ambiguous. 1. Auto config finder 2. Path to a config option 3. config object. I personally would stick to one, its easier to document and understand the behavior. |
I would reduce it to one property |
I would propose going with the least config options as possible as first goal and having the least magic happening as the second goal. So, to reduce the amount of magic, search for And I was going to propose merging |
String doesn’t make any advantage over There are a few use cases that I don’t want to overcomplicate.
webpackConfigFile: './config/webpack.config.js',
webpackConfig: {
resolve: {
alias: {
// Override Styleguidist components
'rsg-components/Logo':
path.join(__dirname, 'styleguide/components/Logo'),
'rsg-components/StyleGuide/StyleGuideRenderer':
path.join(__dirname, 'styleguide/components/StyleGuide'),
},
},
}
webpackConfigFile: './config/webpack.config.js',
webpackConfig: {
entry: [
'babel-polyfill'
]
} So I’d like to have an easy ability to merge multiple configs. We’re using webpack-merge internally, so that would work for example (I’m fine with this solution): webpackConfig: [
require('./config/webpack.config.js'),
{
resolve: {
alias: {
// Override Styleguidist components
'rsg-components/Logo':
path.join(__dirname, 'styleguide/components/Logo'),
'rsg-components/StyleGuide/StyleGuideRenderer':
path.join(__dirname, 'styleguide/components/StyleGuide'),
},
},
}
], (This actually won’t work for new entries.) So |
To me it was at least not obvious that
yeah |
By the way, it's very non-obvious to me that |
Well, initially I was proposing to have just one option instead of 2 as well. I think merge of config should should be explicit to remove magic. It is of course makes it harder for specific use cases but I still believe it's better. I'd stick with auto lookup unless |
OK, some intermediate conclusions:
But we still have more questions:
|
Do u have any other choice considered point 1? |
Ok, I'm lost, how is overriding going to work in this case? |
Webpack supports array and object out of box so the proposal to merge if it's an array is very ambiguous. If you want to merge configs why not include |
Yeah, I think its not a big deal to import a deep-merge function and do it in the config. Its more code, but its explicit. |
@okonet You mean webpack support it as a separate configs? This is a good point. So we’ll just suggest webpack-merge in example (we’ll need a lot of them). So the only question is new entries. |
We're talking about both webpacks, right? v1 and v2? |
@n1313 Yup. Are there any differences that we’re missing? |
@sapegin nah, I'm just making sure that we're talking about the same thing, and that webpack 1 is not being deprecated just yet. |
Nooo, I’d be happy to but it’s too early 😆 |
So what should we do with adding new webpack entries? I can only think of a new config option like this: {
require: [
'babel-polyfill',
'./src/styleguide/some.css',
],
} |
@sapegin why not solve both use cases via normal merge? I feel solving such edge cases will always fail since the next request will be "allow override x". const merge = require('webpack-merge')
module.exports = {
webpackConfig: (config) => {
return merge(config, {
entry: [
'babel-polyfill',
'./src/styleguide/some.css',
]
})
}
} |
You can’t solve via merge because |
1. Search for webpack config only in the root folder. 2. Only search for webpack.config.js and webpackfile.js. 3. Simplify webpack style guide example.
Out in 5.0.0-beta.15. |
1. Search for webpack config only in the root folder. 2. Only search for webpack.config.js and webpackfile.js. 3. Simplify webpack style guide example.
I’m still unsure about the current webpack configuration options in 5.0.0 (
next
branch):It tries to find webpack config by recursively looking for
webpack.dev.config.js
orwebpack.config.js
.As soon as you have
webpackConfigFile
orwebpackConfig
in your style guide config it disable auto load and you have to usewebpackConfigFile
to specify you webpack config location.Problems I see here:
Possible solution:
Behave as close to webpack as possible. They load
webpack.config
orwebpackfile
with different extensions (.js
,.babel.js
) only in the project root folder.Do not disable autoload if
webpackConfig
option is used. ProbablywebpackConfigFile: false
do disable autoload explicitly.Warn if there’s no
webpackConfigFile
orwebpackConfig
and config in the default location not found (just a friendly warning, not an error with exit).If we don’t support
.babel.js
we should document it and recommend to convert config to native Node since Node 4+ supports enough ES6.I’m quite sure about the 1st (except I don’t really believe in usefulness of
.babel.js
thing with Node 4+) but 2nd and 3rd are still not clear for me.I’m trying to find the least surprising behavior. Possible not the most useful. What do you think?
Todo
webpack.config.js
orwebpackfile.js
in the project root folder.webpackConfigFile
.webpackConfig
and config in the default location not found (just a friendly warning, not an error with exit).The text was updated successfully, but these errors were encountered: