0
点赞
收藏
分享

微信扫一扫

Cocos Creator 3.x之自定义npm库(ts版)

一叶随风_c94d 03-04 22:30 阅读 2

一,创建npm库

1,代码

a, toolkit.js

export class Toolkit{
    public printSomething(): void{
        console.log(`this is ts npm lib`);
    }
}

b, index.js

import { Toolkit } from "./toolkit";
export {Toolkit};

2, 编辑tsconfig.jsom

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./dist",
    "strict": true
  }
}

3, 命令:tsc

Cocos Creator 3.x之自定义npm库(ts版)_ts

4, 命令:npm publish, 提交库

Cocos Creator 3.x之自定义npm库(ts版)_库_02

二,nodejs平台测试

1, 命令:npm i npmts-demo-alex

2, 测试代码index.js

// "use strict"
// exports.__esModule = true;

let npm_1 = require("npmts-demo-alex");
let alex = new npm_1.Toolkit();
alex.printSomething();

3, 结果

Cocos Creator 3.x之自定义npm库(ts版)_cocos_03

三,cocos creator 3.x平台测试

1,命令:npm i npmts-demo-alex

2,代码

Cocos Creator 3.x之自定义npm库(ts版)_cocos_04

3, 结果

Cocos Creator 3.x之自定义npm库(ts版)_ts_05


举报

相关推荐

0 条评论