-
Notifications
You must be signed in to change notification settings - Fork 11
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
Move config into an internal object instead of piggy backing on next config #2
Comments
Hi Karolis, I'd like to take a stab at this issue between holidays, do you have any preferences regarding the configuration placement? i was thinking either to wrap plugin's configuration into
Alternatively, the configuration could be placed in a separate file, e.g. Also should I consider backward compatibility? E.g. if the plugin finds a configuration key in top-level of config object, it should show a warning (using |
Hi! That'd be awesome. I would avoid using a separate config file (seems overkill for a plugin configuration). Backwards compatibility is ok to break (we'll bump the version up), because I'd prefer if everyone moved to the new configuration, rather than having to maintain multiple approaches. I think what you suggested should work, keep the plugin config in |
Well, looking at Next's source it seems the warning should be triggered only by the Is it perhaps possible this behavior changed between versions? Anyway I think it's still a good practice to separate the plugin's configuration into an explicit namespace to prevent any possible collisions with other plugins or even Next's configuration. |
Reported here, but the pkg author said they couldn't reproduce, hm.. cyrilwanner/next-compose-plugins#21 |
Okay, I have figured out why this happens; while the compose plugin plays part, as I explain here: cyrilwanner/next-compose-plugins#21 (comment), the main issue with the use of next-img/lib/next-plugin/nextPlugin.js Line 50 in 384581f
By default deepmerge creates a deep clone of objects, therefore the pluginConfig = deepmerge.all([{}, defaults, pluginConfig], { arrayMerge: overwriteMerge, clone: false }) However I think moving the plugin options to a separate property is still the cleanest solution. |
Thanks for looking into this! Maybe we should switch to lodash's const pluginConfig = defaultsDeep(pluginConfig, defaults) Regarding putting the plugin settings into a namespace - what do other plugins do? My impression was that most "official" plugins set the top level config values. What does |
You are right that most plugins, including next-optimized-images or next-mdx-blog keep the options in top-level object. However, next-optimized-images canary introduced a separate configuration file images.config.js (which makes sense since the plugin has been decoupled from Next.js into separate Babel and Webpack plugins). My only concern is the options' names used by this plugin are rather generic enough to cause possible collision with other plugins or future Next.js' options. But I can see it's preferable to keep config compatibility for the time being rather than to unnecessarily future-proof it for now. I will look into |
When I created this issue, ideally I was hoping it would be possible to
keep the config of this plugin in a closure / internally without ever
polluting the next object. So you pass the config with top level keys in
the withImg call, but it never gets merged into the next config. I’m just
not sure that’s possible if making it still compatible with next compose.
Unless maybe its a double call thing withImg(config)().
…On Mon, 28 Dec 2020 at 14:12, Jan Vlnas ***@***.***> wrote:
Regarding putting the plugin settings into a namespace - what do other
plugins do? My impression was that most "official" plugins set the top
level config values. What does next-optimized-images or other 3 popular
plugins do? We should try to do what everyone else is doing, unless
everyone is doing it differently..
You are right that most plugins, including next-optimized-images or
next-mdx-blog
<https://github.com/hipstersmoothie/next-mdx-blog#configuration> keep the
options in top-level object. However, next-optimized-images canary
introduced a separate configuration file images.config.js
<https://github.com/cyrilwanner/next-optimized-images/tree/canary#imagesconfigjs>
(which makes sense since the plugin has been decoupled from Next.js into
separate Babel and Webpack plugins).
My only concern is the options' names used by this plugin are rather
generic enough to cause possible collision with other plugins or future
Next.js' options. But I can see it's preferable to keep config
compatibility for the time being rather than to unnecessarily future-proof
it for now.
I will look into defaultsDeep.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACPGWGAZVN3XMVNKF3PFVTSXCG5TANCNFSM4N6JM7PQ>
.
|
Okay, so I got a bit tangled into this. The problem is that There is discussion in TehShrike/deepmerge#212 to un-deprecate
Yeah, I also though whether that could be a way out. I think it would be possible like this, but it would add alternative behavior in case the compose plugins is not used. Basically:
|
This is to avoid triggering the experimental feature warning:
The text was updated successfully, but these errors were encountered: