angular - ca.select(...).from 不是缩小后的函数
问题描述
在我的Angular应用程序中,我使用的是squel.js,并且在开发模式下使用时效果很好。
但是,当我为生产构建应用程序并尝试使用它时,出现以下错误:
ca.select(...).from 不是函数
在非缩小代码中对应于:
import * as squel from 'squel';
// ...
squel.select().from(...)
解决方案
该问题是由squel.js中的一个错误引起的,该错误会在缩小后阻止使用它。
解决方案(解决方法)
1) 包括 sqlite 作为脚本,angular.json
而不是import
通过将其添加到scripts
数组中来使用projects.myAppName.architect.build.options
:
"scripts": [
"node_modules/squel/dist/squel.min.js"
]
projects.myAppName.architect.test.options
为了修复单元测试也做同样的事情。
2) 现在生产包很好,但我们必须修复类型,以便 ts 编译器也可以工作。
由于我们删除了:
import * as squel from 'squel';
喜欢的所有类型squel.Insert
都会被破坏。
我们需要添加:
declare const squel: Squel & {flavour: null};
现在所有类型如squel.Insert
, squel.Delete
, etc... 将被Insert
, Delete
, etc... 替换,当然我们需要导入它们:
import { Squel, Delete, Insert } from 'squel';
这种方式我们import
只用来导入类型定义而不是整个库。
例子
https://github.com/azerothcore/Keira3/commit/98f191eb59cf9c853dd8a54a845a029c7a4ddef8
推荐阅读
- reactjs - axios 库需要速率限制
- php - PHPmailer 多个邮件 - 503 错误
- mongodb - 在 mongoDB 中使用聚合对项目子句中缺少的路径进行排序
- c++ - 什么时候类型双关指针在实践中是安全的?
- android - LocationCallback 没有被调用
- angular - 角度路由重复窗口
- ios - 使用“使用安全区域布局指南”,图像位于视图中心。视图向左移动
- javascript - Angular 2 路由 - 重定向到不同的应用程序
- bash - Shell-Script 'line 1: color:: command not found'
- java - 如何使用桥接方法实现协变返回类型