将未编译的打字稿库添加到 Craco 配置中

Ste*_*scu 7 typescript reactjs craco

我有一个用 Typescript 编写的“公共库”,我想在更多项目中使用它。我不想从中创建 npm 包,我只想将其作为“未编译的包”导入,但我在设置时遇到问题。我尝试添加 ts-loader 并排除模块,如下所示:

webpackConfig.module.rules.push({
  test: /\.tsx?$/,
  use: 'ts-loader',
  exclude: /node_modules\/((?!common-library).)*$/,
});
Run Code Online (Sandbox Code Playgroud)

但是,这会导致错误:TypeScript 未发出 /path/to/index,tsx 的输出。

我还尝试使用craco-babel-loader https://github.com/rjerue/craco-babel-loader,但是将其添加到插件列表时:

{
  plugin: rewireBabelLoader,
  options: {
    includes: [resolveApp('node_modules/common-library')],
    excludes: [/node_modules/],
  }
},
Run Code Online (Sandbox Code Playgroud)

我得到以下信息:

C:\path\to\app\node_modules\@craco\craco\lib\loaders.js:34
    rules.some((rule, index) => {
          ^

TypeError: rules.some is not a function
Run Code Online (Sandbox Code Playgroud)