封装组建类库

package.json

{
  "name": "库名称",
  每次 npm publish 之前要先修改版本号  
  "version": "1.0.0",
  项目描述
  "description": "",
  入口文件
  "main": "./dist/uu-utils.js",
  仓库地址
  "repository": "https://github.com/",
  脚本
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build:watch": "webpack --watch"
  },
  关键词
  "keywords": [
    "array",
    "object",
    "function",
    "string",
    "axios",
    "promise",
    "event-bus"
  ],
  作者名称
  "author": "Rck",
  开源协议
  "license": "ISC",
  "dependencies": {},
  "devDependencies": {
    "webpack": "^5.69.1",
    "webpack-cli": "^4.9.2"
  }
}

webpack.config.js

const path = require('path');

module.exports = {  
    开发模式
    mode: 'development',
    可以进行压缩,方便引入
    mode: 'production',
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        // filename: 'uu-utils.js',
        filename: 'uu-utils.min.js',
        // 向外暴露的对象的名称
        library: 'uuUtils',
        // 打包生成库可以通过 esm/commonjs/requirejs的语法引入
        libraryTarget: 'umd'
    },
    // 可以写入库依赖的外部依赖,不会打包进你的库,但是需要的
    externals: {

    }
}

上传 npm

  1. 注册 npm 账号
  2. 终端登录 npm login 输入账号密码邮箱
  3. 推到 npm 仓库 npm publish

上传到 github

  1. 创建 github 仓库
  2. git init
  3. git add .
  4. git commit -m ‘first’
  5. git remote add origin 改变git源
  6. git push origin master
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值