【发布时间】:2020-07-10 00:32:55
【问题描述】:
我的文件夹结构是
src/lib/componentA.tsx
src/index.tsx
使用microbundle-crl 运行构建后,我得到关注
dist/lib/componentA.d.ts /* problem is that no js file is created at this path*/
dist/index.js
我也期待dist/lib/componentA.js 文件,但它永远不会被创建,所有逻辑都连接在一个我不想要的 index.js 中。
我的tsconfig如下:
{
"compilerOptions": {
"outDir": "dist",
"module": "esnext",
"lib": ["dom", "esnext"],
"moduleResolution": "node",
"jsx": "react",
"sourceMap": true,
"declaration": true,
"esModuleInterop": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowSyntheticDefaultImports": true
},
"include": ["src"],
"exclude": ["node_modules", "dist", "example"]
}
感谢任何帮助
【问题讨论】:
-
你在创建一个 React 库吗?如果是,为什么编译到一个 js 文件有问题?如果您在不同的文件中定义了不同的类型并且想要公开它们,则可以使用 index.ts 来进行必要的导出,例如 this。
-
@sidecus 我想访问单个组件 import ComponentA from 'mymodule/ComponentA' 而不是 import { ComponentA } from 'mymodule'。我正在动态导入它们,这使它更具可读性。
-
很公平。这不是通过 tsconfig.json 控制的,而是由 package.json 控制的。您可以尝试将源属性更新为数组,如下所示: "source": ["src/componentA.ts","src/componentB.ts"],
-
感谢您的快速回复。稍后会试一试,目前决定使用第二种方法
-
@vcDevG 什么对你有用?我也遇到了这个问题。
标签: reactjs typescript