-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Register global components in themes #281
Comments
Should be closed. The requested feature Lines 80 to 81 in 31b8feb
Lines 177 to 181 in 31b8feb
|
If you read his requirement carefully, you will find that he just want to leverage the functionality that all components at |
You are right, I misunderstood what he requests. This feature may need some discussions. |
Hello everyone! I have tried to come up with a simple solution for this scenario and I have drafted these changes on async function genComponentRegistrationFile ({ sourceDir }) {
function genImport (file, componentPath) {
const name = fileToComponentName(file)
const baseDir = path.resolve(sourceDir, componentPath)
const absolutePath = path.resolve(baseDir, file)
const code = `Vue.component(${JSON.stringify(name)}, () => import(${JSON.stringify(absolutePath)}))`
return code
}
const components = (await resolveComponents(sourceDir, '.vuepress/components')) || []
const customThemeComponents = (await resolveComponents(sourceDir, '.vuepress/theme/components')) || []
const componentsStr = components.map(f => genImport(f, '.vuepress/components')).join('\n')
const customThemeComponentsStr = customThemeComponents.map(f => genImport(f, '.vuepress/theme/components')).join('\n')
return `import Vue from 'vue'\n${componentsStr}\n${customThemeComponentsStr}`
} Adding the component path as a second parameter to both I did some testing locally and I believe it achieves what is intended 👍 What do you think of this approach could it be viable? If so I would be happy to open a PR 😄 |
@ulivz, @meteorlxy can you give some feedback on this idea? 😉 |
I suggest to use In fact, I'm waiting for the first plugin API draft these days 😅 |
Hello again! Thanks for the tip @meteorlxy, I made some changes to make use of |
Vue Press version: 0.8.4
In
.vuepress/
components are automatically registered when they're placed incomponents/
. As a developer, my assumption was that thetheme/
folder would have a similar feature.Components can be registered with a pattern like this:
But it would be nice if the theme could mirror functionality of
.vuepress/
structures likecomponents/
The text was updated successfully, but these errors were encountered: