需要帮助发布 NPM Typescript 包

问题描述

我已发布该库,但出现问题。我需要做这样的事情来访问我的代码

const {
    default: { getContrast },} = require('@akashshyam/color-utilities/lib/index');

console.log(getContrast('#ffffff'));

有两个问题:

  1. 我需要使用 lib 文件夹,它应该只是 @akashshyam/color-utilities/index
  2. 我导出了一个认对象。但是要访问我需要使用 default 属性

这里是 package.json

{
    "main": "lib/index.js","types": "lib/index.d.ts","scripts": {
        "build": "tsc","test": "mocha --reporter spec --require ts-node/register src/**/*.test.ts","prepare": "npm run build","lint": "eslint","format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"","prepublishOnly": "npm run test && npm run lint","preversion": "npm run lint","version": "npm run format && git add .","postversion": "git push && git push --tags"
    },"files": [
        "/lib"
    ],}

现在,编译为 vanilla JS 之前和之后的文件夹结构:

enter image description here

index.js 之外的所有文件都有一个或多个导出的函数。我正在 index.js 中创建一个包含所有函数的对象:

import { getContrast } from './colorContrast';
import { HSLToHex,HSLToRGB,RGBToHSL,RGBToHex,hexToHSL,hexToRGB } from './colorConversion';
import { separateHSL,separateRGB } from './colorSeparation';
import { validateHSL,validateHex,validateRGB } from './colorValidators';

export default {
    getContrast,HSLToHex,hexToRGB,separateHSL,separateRGB,validateHSL,validateRGB,};

另外,我想将这些多个文件合并为一个文件并缩小代码。我目前正在使用打字稿编译器来编译这些文件。我试过 webpack 但我有一些错误。我愿意使用捆绑器,但请提供配置。我希望你们能对这些观点中的任何一点有所了解。提前致谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)