简世博客

一个简单的世界——博客空间,写了一些Android相关的技术文章,和一些点滴的想法

0%

打npm包的步骤

打npm包的步骤

  1. 使用parcel编译,parcel build ./index.ts –no-source-maps –target node –bundle-node-modules

加上–no-minify可以设置不混淆

  1. package 中配置name , version ,main ,files 等
    下面是一个例子:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    {
    "name": "mypackage",
    "version": "0.0.1",
    "main": "dist",
    "files": [
    "common",
    "dist"
    ],
    "scripts": {
    "build": "parcel build ./index.ts --no-source-maps --target node --bundle-node-modules --no-minify",
    "dev": "parcel watch ./index.ts --no-source-maps --target node --bundle-node-modules",
    "clean": "rm -rf node_modules && rm -rf dist && rm -rf .cache"
    },
    "dependencies": {
    },
    "devDependencies": {
    "@types/node": "^14.14.22",
    "parcel-bundler": "^1.12.4",
    "typescript": "^4.1.3"
    },
    "publishConfig": {
    "registry": "https://registry.npm.alibaba-inc.com"
    }
    }

  2. https://www.npmjs.com/注册 npm账号

  3. 本地登录 npm账号 npm login

  4. 在仓库目录使用 npm publish 发布包。


本地开发时,可以使用npm link功能来本地依赖库

  1. 在仓库目录中使用npm link命令
  2. 再到调用代码的仓库使用 npm link mypackagename 即可

另外,使用parcel watch ./index.ts --no-source-maps --target node --bundle-node-modules 可以让库中代码修改后自动编译,方便本地依赖开发。