{"name":"@rc-component/father-plugin","version":"2.1.1","keywords":[],"license":"MIT","_id":"@rc-component/father-plugin@2.1.1","maintainers":[{"name":"zombiej","email":"smith3816@gmail.com"},{"name":"afc163","email":"afc163@gmail.com"},{"name":"madccc","email":"1075746765@qq.com"},{"name":"peachscript","email":"scdzwyxst@gmail.com"}],"homepage":"https://github.com/react-component/father-plugin#readme","bugs":{"url":"https://github.com/react-component/father-plugin/issues"},"dist":{"shasum":"a76376ba16e919ccb929951df5f3d4cbb60ab8e7","tarball":"http://registry-npm.ywwl.com/@rc-component/father-plugin/download/@rc-component/father-plugin-2.1.1.tgz","fileCount":5,"integrity":"sha512-ea/J+9fnUdZNY4GJK0QgoS83bKctXTbOTE8/smM0Mrtd32j8a1tbRqgySC83NLY5fmql1pT/YbKaSoLQE1JgLg==","signatures":[{"sig":"MEUCIBEzbDz6m5jcwM+0Zj8i49VAEKbX+RHJWIhhxeJDPHUGAiEAlrhzktTneq1xzZqyzD+mcCkKIAiveSJZOO41DeOKZJE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10728,"size":3773,"noattachment":false,"key":"/@rc-component/father-plugin/-/@rc-component/father-plugin-2.1.1.tgz"},"main":"dist/index.js","authors":["PeachScript <scdzwyxst@gmail.com>"],"gitHead":"1fc9918667f9dcb6f7883e23e65674f9b8c09889","scripts":{"dev":"father dev","build":"cross-env CHECK_TS_ONLY=1 father build","lint:es":"eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"","prepare":"husky install","prepublishOnly":"cross-env CHECK_TS_ONLY=1 father doctor && npm run build"},"_npmUser":{"name":"zombiej","email":"smith3816@gmail.com"},"commitlint":{"extends":["@commitlint/config-conventional"]},"repository":{"url":"git+https://github.com/react-component/father-plugin.git","type":"git"},"_npmVersion":"10.8.2","description":"The father plugin for all react-component projects","directories":{},"lint-staged":{"*.{js,jsx}":["eslint --fix","prettier --write"],"*.{ts,tsx}":["eslint --fix","prettier --parser=typescript --write"],"*.{md,json}":["prettier --write --no-error-on-unmatched-pattern"]},"_nodeVersion":"22.5.1","dependencies":{"chalk":"^4.1.2","eslint":"^8.23.0","fs-extra":"^11.3.0","@typescript-eslint/parser":"^8.28.0","@typescript-eslint/eslint-plugin":"^8.28.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"husky":"^8.0.1","father":"^4.1.0","prettier":"^2.7.1","cross-env":"^7.0.3","@umijs/lint":"^4","lint-staged":"^13.0.3","@types/eslint":"^8.56.12","@commitlint/cli":"^17.1.2","@types/fs-extra":"^11.0.4","prettier-plugin-packagejson":"^2.2.18","@commitlint/config-conventional":"^17.1.0","prettier-plugin-organize-imports":"^3.0.0"},"peerDependencies":{"father":"^4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/father-plugin_2.1.1_1743064261168_0.18615903529166977","host":"s3://npm-registry-packages-npm-production"},"readme":"<div align=\"center\">\n  <h1>@rc-component/father-plugin</h1>\n  <p><sub><a href=\"https://ant.design\"><img alt=\"Ant Design\" height=\"14\" src=\"https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg\" style=\"vertical-align: -0.125em;\" /></a> Ant Design 生态的一部分。</sub></p>\n  <p>🧱 rc-component 包共享的 father 构建插件。</p>\n\n  <p>\n    <a href=\"https://npmjs.org/package/@rc-component/father-plugin\"><img alt=\"NPM version\" src=\"https://img.shields.io/npm/v/@rc-component/father-plugin.svg?style=flat-square\"></a>\n    <a href=\"https://npmjs.org/package/@rc-component/father-plugin\"><img alt=\"npm downloads\" src=\"https://img.shields.io/npm/dm/@rc-component/father-plugin.svg?style=flat-square\"></a>\n    <a href=\"https://bundlephobia.com/package/@rc-component/father-plugin\"><img alt=\"bundle size\" src=\"https://img.shields.io/bundlephobia/minzip/%40rc-component%2Ffather-plugin?style=flat-square\"></a>\n    <a href=\"https://github.com/react-component/father-plugin/actions/workflows/test.yml\"><img alt=\"build status\" src=\"https://github.com/react-component/father-plugin/actions/workflows/test.yml/badge.svg\"></a>\n    <a href=\"https://app.codecov.io/gh/react-component/father-plugin\"><img alt=\"Codecov\" src=\"https://img.shields.io/codecov/c/github/react-component/father-plugin/main.svg?style=flat-square\"></a>\n  </p>\n</div>\n\n<p align=\"center\"><a href=\"./README.md\">English</a> | 简体中文</p>\n\n## 亮点\n\n| 方向 | 支持                                    |\n| ---- | --------------------------------------- |\n| 定位 | rc-component 包共享的 father 构建插件。 |\n| 包名 | `@rc-component/father-plugin`           |\n| 发布 | `@rc-component/np` / `rc-np`            |\n\n## 安装\n\n```bash\nnpm install @rc-component/father-plugin --save-dev\n```\n\n## 用法\n\n```ts | pure\nimport { defineConfig } from 'father';\n\nexport default defineConfig({\n  plugins: ['@rc-component/father-plugin'],\n});\n```\n\n## API\n\n### 原生 ESM 的默认导入\n\n`cjsDefaultInterop` **默认关闭**。不配置或设为 `false` 时，插件不注册 interop 编译处理，也不加载相关检查依赖，保留原有编译产物和导入语义。\n\n需要让转译后的 CommonJS 默认导入在原生 Node ESM 中工作时，由组件库显式开启。使用 Father 4.6.37 或更高版本：\n\n```ts | pure\nimport type {} from '@rc-component/father-plugin';\nimport { defineConfig } from 'father';\n\nexport default defineConfig({\n  plugins: ['@rc-component/father-plugin'],\n  cjsDefaultInterop: true,\n  esm: { platform: 'node', autoExtension: true },\n});\n```\n\n类型导入为 `defineConfig` 加载插件的配置类型，不产生运行时导入。开关位于配置顶层，与 `esm`、`cjs` 同级。切换开关也会改变 Father 的文件构建缓存键。\n\n开启后，仅对 **Node ESM 产物** 中能静态识别的转译后 CommonJS 依赖处理默认导入。插件按照 Node 的 **import** 条件解析依赖入口，检查 `__esModule` 和 `default` 导出，全程不执行依赖代码。不维护包名白名单，支持带 scope 的包、包子路径和可静态识别的 CommonJS 转导出入口。\n\nFather 继续使用 Node 平台默认的 esbuild；显式选择 Babel 或 SWC 时也会在 TypeScript/JSX 编译完成后执行相同的处理，并将 source map 合并回原始源码。每个涉及的产物文件只生成一个小型兼容函数，组件源码保持普通默认导入，包括 `import { default as Name }`。\n\n构建时识别为原生 ESM 的入口和普通 CommonJS 导出保持原样。规则不处理命名导入、命名空间导入、纯类型导入、相对路径、内置模块、动态导入以及消费方源码中的依赖再导出语句。无法解析的依赖、无法静态识别的导出结构以及检查用解析器不支持的产物语法也保持原样。面向浏览器的构建和 CommonJS 构建继续使用原有编译产物。\n\n**开启此选项会改变默认导入语义。** 对于识别到的 CommonJS 依赖，`import pkg from 'legacy'` 拿到的是内部的 `default` 值，原本的 CommonJS 导出对象会被解包。因此，已有的 `pkg.default()` 调用或对该对象其他属性的访问需要先检查。如果构建时识别为 CommonJS，下游实际却选择了原生 ESM 入口，生成的局部变量会保存初始值，无法反映默认导出的后续更新；运行时检查不能保留这种情况下的 ESM 实时绑定。组件库应验证其支持的消费方式后再开启。\n\n这是一项过渡措施，待依赖提供原生 ESM 入口后可移除。产物仍会在运行时检查导出值。解析相关依赖只在组件库构建时运行，产物不会额外导入 helper 包。\n\n| 名称 | 默认值 | 说明 |\n| --- | --- | --- |\n| `plugins` | — | 在 father 配置中注册 `@rc-component/father-plugin`。 |\n| `cjsDefaultInterop` | `false` | 显式开启 Node ESM 产物的 CommonJS 默认导入兼容处理。 |\n\n## 本地开发\n\n```bash\nnpm install\nnpm run lint\nnpm run build\n```\n\n## 发布\n\n```bash\nnpm run prepublishOnly\n```\n\n发布流程通过 `@rc-component/np` 提供的 `rc-np` 命令处理。\n\n## 许可证\n\n@rc-component/father-plugin 基于 [MIT](./LICENSE) 协议发布。\n","publish_time":1743064261387,"_cnpm_publish_time":1743064261387,"dist-tags":{"alpha":"1.2.0-alpha.0","latest":"2.4.0"}}