2016-12-29 80 views
3

我有一個index.js文件與創建NPM包:如何從.vue文件

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

我要發佈這爲npm package,使我可以通過npm install my-component

當我嘗試使用這個組件通過從編譯後的js文件中導入組件進行測試得到[Vue warn]: Failed to mount component: template or render function not defined

但是工作正常時我從.vue文件導入。

回答

3

您只需在目錄中添加一個package.json,並在main字段package.json添加主要入口點到您的組件。

你可以看看這個簡單的npm組件:vue-just-another-dropdown,這會給你更多的想法。

+1

當我從編譯的js文件導入得到「[Vue警告]:無法裝入組件:模板或渲染功能未定義」。 – mrabbani

+0

你可以發佈這個組件的整個代碼,你在哪裏使用它,可能會有一些其他的錯誤。 – Saurabh

+0

@mrabbani而不是'module.exports = MyComponent;'嘗試'導出默認的MyComponent' – Saurabh