npm发布包以及更新包还有需要注意的几点问题(这里以发布vue插件为例)


前言

在此之前,你需要去npm官网注册一个属于自己的账号,记住自己的账户名以及密码、邮箱,后面会用的到。
第一步,安装webpack简易框架

vue init webpack-simple marquee

这里会用到vue init 命令,如果你的cli版本是3或者以上,那么在此之前你需要安装vue/cli-init

npm install -g @vue/cli-init

vue init 的运行效果将会跟 vue-cli@2.x 相同

第二步,封装Vue插件
1、安装完成后,会出现以下目录即可成功

marquee/
├── index.html
├── package.json
├── README.md
├── .babelrc
├── .editorconfig
├── .gitignore
├── src
│ ├── App.vue
│ ├── assets
│ │ └── logo.png
│ └── main.js
└── webpack.config.js

2、接下来,我们在src文件夹下创建一个名叫marquee的文件夹,在文件夹里面创建marquee.vue和index.js

marquee/
├── index.html
├── package.json
├── README.md
├── .babelrc
├── .editorconfig
├── .gitignore
├── src
│ ├── App.vue
│ ├── marquee
│ │ └── marquee.vue
│ │ └── index.js
│ ├── assets
│ │ └── logo.png
│ └── main.js
└── webpack.config.js

3、开始在marquee.vue封装Vue插件了

>
  
="marquee-wrap"> <!-- 滚动内容 -->
="scroll">

="marquee">{{text}}</p> <!-- 文字副本 -->

="copy"></p> </div> <!-- 为了计算总文本宽度,通过css在页面中隐藏 -->

="getWidth">{{text}}</p> </div> </template>

更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/119924268