JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q22020F
  • License ISC

publish demo

Package Exports

  • npm-publish-demos
  • npm-publish-demos/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (npm-publish-demos) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

概览

  1. 创建项目
  2. 编写sdk代码
  3. 打包输出
  4. 登录npm账户
  5. 发布

创建项目

执行npm init -y生成package.json文件.

  1. 填写项目名称、作者、关键词等信息。

项目目录

├── dist ##打包结果
|  ├── index.d.ts
|  ├── index.esm.mjs
|  ├── index.js
|  ├── index.modern.mjs
|  └── index.umd.js
├── node_modules
|  ├── @babel
|  ├── @types
├── package.json
├── pnpm-lock.yaml
├── README.md
├── src
|  └── index.ts # 源代码
└── tsconfig.json

安装依赖

用到什么就装什么.

pnpm install typescript
pnpm install ts-node # 编译ts文件[dev]
pnpm install microbundle # 打包ts文件

示例代码

export const add = (a: number, b: number) => {
  return a + b;
}

export const minus = (a: number, b: number) => {
  return a - b;
}

export const multiple = (a: number, b: number) => {
  return a * b;
}

export const divide = (a: number, b: number) => {
  return a / b;
}

export const stringToUpperCase = (str: string) => {
  return str.toUpperCase();
}

package.json

{
  "name": "npm-publish-demos",
  "version": "1.0.2",
  "description": "publish demo",
  "source": "src/index.ts",
  "main": "./dist/index.js",
  "scripts": {
    "dev": "microbundle watch",
    "build": "microbundle --no-sourcemap"
  },
  "keywords": [
    "example"
  ],
  "author": "ryan.ke",
  "license": "ISC",
  "devDependencies": {
    "microbundle": "^0.15.1",
    "typescript": "^4.8.4"
  },
  "files": [
    "dist"
  ]
}

登录npm

执行npm login,输入"用户名、密码、邮箱".
19d358e9135543099964ca6d32d15aea.png

发布

执行npm publish,发布完成.
dc3e499069644f75a0d20afb302632dd.png

使用

npm install npm-publish-demos

import { add } from 'npm-publish-demos';
const result = add(1, 2);
console.log('result', result); // 3