{"id":22105236,"url":"https://github.com/zhangyu1818/lib-tool","last_synced_at":"2025-03-24T02:44:57.636Z","repository":{"id":57290090,"uuid":"370025560","full_name":"zhangyu1818/lib-tool","owner":"zhangyu1818","description":"Zero configuration, an easy way to package a component library.","archived":false,"fork":false,"pushed_at":"2021-07-18T04:29:00.000Z","size":532,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-29T08:44:54.921Z","etag":null,"topics":["builder","package-builder"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhangyu1818.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-23T10:44:07.000Z","updated_at":"2021-07-19T01:38:49.000Z","dependencies_parsed_at":"2022-08-25T07:34:19.940Z","dependency_job_id":null,"html_url":"https://github.com/zhangyu1818/lib-tool","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyu1818%2Flib-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyu1818%2Flib-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyu1818%2Flib-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyu1818%2Flib-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhangyu1818","download_url":"https://codeload.github.com/zhangyu1818/lib-tool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245200674,"owners_count":20576673,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["builder","package-builder"],"created_at":"2024-12-01T06:40:00.771Z","updated_at":"2025-03-24T02:44:57.618Z","avatar_url":"https://github.com/zhangyu1818.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lib-tool\n\n零配置，用简单的方式来打包一个组件库 📦。\n\n**功能**\n\n- 零配置。\n- 支持 JavaScript、TypeScript、React。\n- 同时支持 ESM 和 CJS 的打包。\n- 同时支持 Less、Sass、CSS 的打包。\n\n## 安装\n\n**npm**\n\n```sh\nnpm install -D lib-tool\n```\n\n**yarn**\n\n```sh\nyarn add lib-tool --dev\n```\n\n### 使用\n\n在**package.json**中引用。\n\n```js\n{\n  \"scripts\": {\n    \"build\": \"lib-tool\"\n  }\n}\n```\n\n或直接执行命令。\n\n```sh\n$ lib-tool\n```\n\n默认情况下，`lib-tool`会以匹配模式来打包，即会打包入口目录下的所有文件。\n\n`lib-tool`是文件到文件进行编译，这代表输出的结构会和输入的结构一致，而不会打包为一个`bundle.js`文件。\n\n## 配置文件\n\n如果你想添加更多配置，那么可以创建配置文件。\n\n新建`toolrc.js`或`toolrc.ts`，推荐使用`.ts`文件配置，因为可以获得类型提示。\n\n```typescript\n// toolrc.ts\nimport type { UserConfig } from 'lib-tool'\nexport default {\n  entry: 'components/index.tsx',\n  lessOptions: {\n    javascriptEnabled: false, // 默认为 true\n  },\n  fileFilter: (filePath) =\u003e !filePath.includes('ignore_dir'),\n} as UserConfig\n```\n\n## 配置项\n\n**entry** `string`\n\n打包入口，在`match`模式下可为入口目录，`dependence`模式下为入口文件路径，默认情况会寻找`src/index.(js|jsx|ts|tsx)`。\n\n**outDir** `OutDir`\n\n打包输出目录，`key`为打包格式，默认值：\n\n```js\n{\n  esm: 'es',\n  cjs: 'lib',\n}\n```\n\n**mode** `Mode`\n\n打包分为`match`和`dependence`两种模式，默认为`match`模式。\n\n- `match` 模式直接以入口目录作为匹配，打包目录下所有文件。\n- `dependence`模式只根据入口文件所依赖的文件打包。\n\n**pattern** `string`\n\n寻找文件的匹配符，只在`match`模式下生效，默认值：`**/*.*(js|ts|jsx|tsx)`。\n\n**copyStyles** `boolean`\n\n是否拷贝原样式文件到输出目录，默认为`false`。\n\n**babelConfig** `(format: Format) =\u003e TransformOptions`\n\n自定义`babel`配置项，`format`为当前的打包格式，`cjs`或`esm`，默认配置：\n\n```js\n{\n    presets: [\n      [\n        require.resolve('@babel/preset-typescript'),\n        {\n          isTSX,\n          allExtensions: isTSX,\n        },\n      ],\n      require.resolve('@babel/preset-react'),\n      [\n        require.resolve('@babel/preset-env'),\n        {\n          modules: format === 'esm' ? false : 'auto',\n          targets: {\n            browsers: ['last 2 versions', 'Firefox ESR', '\u003e 1%', 'ie \u003e= 11'],\n          },\n        },\n      ],\n    ],\n  }\n```\n\n**tsConfigPath** `string`\n\n`ts`配置文件路径，`dependence`下生效，默认寻找根目录`tsconfig.json`。\n\n**webpackConfigPath** `string`\n\n`webpack`配置文件路径，`dependence`下生效，默认寻找根目录`webpack.config.js`。\n\n**filter** `(path: string) =\u003e boolean`\n\n过滤文件，可用于只打包某类文件。\n\n**lessOptions** `Less.Options`\n\n`less`的配置。\n\n**sassOptions** `SassOptions`\n\n`sass`的配置。\n\n## Cli\n\n`lib-tool ` 执行打包。\n\n- `--entry` 打包入口。\n- `--mode` 打包模式。\n- `--outDir` 输出目录。\n- `--format`打包格式。\n\nExample:\n\n```sh\nlib-tool --entry entry/index.ts --mode dependence --format esm --outDir dist\n```\n\n## 多配置\n\n配置文件可以导出一个多配置数组。\n\nExample:\n\n依赖打包`components/index.tsx`以`esm`格式打包到`dist`目录，打包`components`目录下所有`less`文件到`styles`目录。\n\n```typescript\nimport { UserConfig, babelConfig } from \"lib-tool\";\n\nexport default [\n  {\n    entry: \"components/index.tsx\",\n    outDir: {\n      esm: \"dist\",\n    },\n    mode: \"dependence\",\n    babelConfig: (format) =\u003e ({\n      ...babelConfig(format),\n      plugins: [\n        [\n          \"module-resolver\",\n          {\n            root: \".\",\n            alias: {\n              \"@utils\": \"./components/utils\",\n            },\n          },\n        ],\n      ],\n    }),\n  },\n  {\n    entry: \"components\",\n    outDir: {\n      esm: \"styles\",\n    },\n    filter: (path) =\u003e path.endsWith(\".less\"),\n  },\n] as UserConfig[];\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangyu1818%2Flib-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhangyu1818%2Flib-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangyu1818%2Flib-tool/lists"}