vue-cli3打npm包爬坑日記

vue create xxxx    創建項目(文檔地址:https://cli.vuejs.org/zh/guide/creating-a-project.html#vue-create

按正常開發寫一個組件 。。。

使用install函數把組件做成插件方便調用

例:

文件目錄

index.js 代碼  (自己針對自己的組件做靈活改動)

import UnifiedValidator from './index.vue'

/* istanbul ignore next */
UnifiedValidator.install = function(Vue) {
  Vue.component(UnifiedValidator.name, UnifiedValidator);
};

export default UnifiedValidator;

package.json 文件配置如下

打包命令查看 文檔 https://cli.vuejs.org/zh/guide/build-targets.html#%E5%BA%94%E7%94%A8

到此組件寫完了,  運行yarn component 就打包完成組件啦^ ^

 

創建npm賬號   https://www.npmjs.com  。。。

npm addUser

Username: 用戶名

Password: 密碼

Email: 郵箱  

以上操作完成後 (郵箱需要校驗哦)

上傳到npm 回到項目根目錄  運行npm publish  就可以了

以下爲爬坑過程:

code E402 

402 Payment Required - PUT http://registry.npmjs.org/@dinghx%2funifiedValidator - You must sign up for private packages

這是因爲包名是 @xxx/xxxx   npm會認爲要發佈私包,私包需要收費,需將發佈命令改成: npm publish --access public

code E403  沒權限發佈

npm ERR! [no_perms] Private mode enable, only admin can publish this module [no_perms] Private mode enable, only admin can publish this module: your-package

這個是你的源設置成第三方源的時候纔有可能發生,比如設置了淘寶源就可能會導致該問題。只要把源改回默認的就可以了,如下: npm config set registry http://registry.npmjs.org

 

you must verify your email before publishing a new package: https://www.npmjs.com/email-edit

這是組件需要重新打包

 

npm ERR! Package name too similar to existing packages; try renaming your package to '@dinghx/captcha' and publishing with 'npm publish --access=public' instead : your-package

這是包名過於相似,需要修改包名

 

npm ERR! you must verify your email before publishing a new package: https://www.npmjs.com/email-edit : your-package

這是郵箱沒有校驗,登錄https://www.npmjs.com   重新發起郵箱驗證

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章