【问题标题】:React Typescript with microbundle-crl doesnot create js file for files other than main file使用 microbundle-crl 反应 Typescript 不会为除主文件以外的文件创建 js 文件
【发布时间】: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


【解决方案1】:

请注意,正在运行的 jest 将修改您的 tsconfig.js 文件。

我必须手动覆盖 "allowJs": false 才能使我的类型定义正常工作。可能是类似的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    相关资源
    最近更新 更多