将 Vue 组件暴露给外部项目 [英] Expose Vue component to outside projects
问题描述
我正在尝试探索如何在不发布到 NPM 的情况下将我的 Vue 组件公开给其他项目.
I am trying to explore how to expose my Vue component to other projects without publishing to NPM.
我可以找到以下链接,其中显示了如何将 Vue 组件发布到 NPM:how-to-publish-your-vue-js-component-on-npm-62b67dfb3e58
I am able to find the below link which shows how to publish a Vue component to NPM : how-to-publish-your-vue-js-component-on-npm-62b67dfb3e58
但我不想发布到 NPM.相反,我想在另一个本地项目中使用创建的组件.
But I don't want to publish to NPM. Instead, I want to use the created component in another local project.
推荐答案
你可以拥有一个私有仓库 package.json
You can have a private repository in you package.json
所以带有.vue
组件的库
{
"name": "my-package-with-components",
"version": "1.0.0",
"files": [
"lib/js/components/**.vue"
]
}
在你想使用这些组件的项目中
In the project where you want to use those components
{
"devDependencies": {
"my-package-with-components": "git+ssh://git@my/repo.git#master",
}
}
在您的应用程序脚本中,您可以导入 .vue 文件
In you application script you can import the .vue files
import SpecialComponent1 from 'my-package-with-components/lib/js/components/SpecialComponent1.vue';
import SpecialComponent2 from 'my-package-with-components/lib/js/components/SpecialComponent2.vue';
Vue.component('special-component-1', SpecialComponent1);
Vue.component('special-component-2', SpecialComponent2);
您可以使用 npm link
cd mylib/ && npm link
cd ../myapp && npm link mylib
这篇关于将 Vue 组件暴露给外部项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!