简体   繁体   English

如何从.vue文件创建NPM包

[英]How to Create NPM packages from a .vue file

I have a index.js file with: 我有一个index.js文件:

import MyComponent from './components/MyComponent.vue';
module.exports = MyComponent;

I want to publish this as npm package so that i can use this component by npm install my-component 我想将它作为npm package发布,以便我可以通过npm install my-component使用这个npm install my-component

When i try to test by importing component from compiled js file got [Vue warn]: Failed to mount component: template or render function not defined 当我尝试通过从编译的js文件导入组件进行测试得到[Vue warn]: Failed to mount component: template or render function not defined

But work fine when i import from .vue file. 但是当我从.vue文件导入时工作正常。

You just need to add a package.json in the directory and in main field of package.json add primary entry point to your component. 您只需要在package.json的目录和main字段中添加package.json即可为组件添加主入口点。

You can have a look at this simple npm component: vue-just-another-dropdown , which will give you more idea. 你可以看看这个简单的npm组件: vue-just-another-dropdown ,它会给你更多的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM