When extending a theme, I would like to pass a themeConfig object to my parent theme with pre-defined values. (i.e a sidebarDepth).
It allows a child theme config to pre-fill some config for it's parent theme.
Right now the possibilities are:
.vuepress/config.js : User config where it defines his themeConfig values. (i.e the sidebarDepth).
.vuepress/theme/index.js: Child theme extending from the parent theme (i.e @vuepress/theme-default). Here we can only get the user config and pass it to our child theme.
I would like the possibility to pass some values to the parent config. (i.e force a sidebarDepth to be 0)
A new key in the theme/index.js file to pass in config to the parent theme.
I think adding a new key to the theme/index.js file is a valid option.
For now we have the extend key like so:
module.exports = {
extend: "@vuepress/theme-default",
}
we could add another key like parentThemeConfig:
module.exports = {
extend: "@vuepress/theme-default",
parentThemeConfig: {
sidebarDepth: 0
}
}
could be replaced with entry = pluginAPI.normalizePlugin('theme', path, theme.entry.parentThemeConfig || ctx.themeConfig)
(some more code change need to be done in the function calls above, but that's the big picture I have in mind)
Yes, that would be fine if we agree in a correct approach beforehand.
I am not sure if it 's actually needed. At least it has a work around here.
For plugins, just config them, it will overide the parent theme configuration.
For others, note that themeConfig is a computed value in components. So just make a function editing it in your theme/index.js.
E.G.:
module.exports = (themeConfig) =>{
themeConfig.sidebarDepth = 0;
};
@Mister-Hope thanks! :clap:
That's so simple.. :see_no_evil:
I don't know how I didn't thought about this one.
I lost at least 2 hours trying so many different options..
Maybe we should update the docs to reflect this in the extend a theme section.
Thanks, my theme/index.js would be:
module.exports = themeConfig => {
themeConfig.sidebarDepth = themeConfig.sidebarDepth || 0
return {
extend: "@vuepress/theme-default"
}
}
By the way, this issue may help you #1938
Most helpful comment
I am not sure if it 's actually needed. At least it has a work around here.
For plugins, just config them, it will overide the parent theme configuration.
For others, note that themeConfig is a computed value in components. So just make a function editing it in your
theme/index.js.E.G.: