reactjs - 将未编译的打字稿库添加到 Craco 配置
问题描述
我有一个用 Typescript 编写的“公共库”,我想在更多项目中使用它。我不想从中创建一个 npm 包,我只想将它作为“未编译的包”导入,但我在设置它时遇到了麻烦。我尝试添加 ts-loader 并排除这样的模块:
webpackConfig.module.rules.push({
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules\/((?!common-library).)*$/,
});
但是,这会导致错误: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/],
}
},
我得到以下信息:
C:\path\to\app\node_modules\@craco\craco\lib\loaders.js:34
rules.some((rule, index) => {
^
TypeError: rules.some is not a function
解决方案
推荐阅读
- rust - 如何修复`无法将jobserver管道容量从4096增加到8192;jobserver 否则可能会出现来自 cargo/rustc 的死锁错误
- c# - 如何在 Linq C# 中使用嵌套字典对列表进行排序?
- google-apps-script - Apps 脚本需要检查权限并请求 onOpen
- sql - SQL 查询性能 - UI 响应性问题
- unix - 在特定行中输入编辑时打开 FZF,其中包含目录中的文件行
- javascript - 编程我的不和谐机器人时遇到问题
- nativescript - Nativescript 7.x iOS 静态库
- javascript - 无法在 Next.js 中声明 Object.prototype
- .net - UWP BackgroundTransfer StartAsync 但不等待任务完成
- machine-learning - ResNet50:层global_average_pooling2d_2的输入0与层不兼容:预期ndim=4,发现ndim=2