[英]How to import a Javascript library in a List Functions
Is there a way to import "external" Javascript libraries for use in List Functions
in CouchDB? 有没有办法导入“外部”Javascript库以便在CouchDB中的
List Functions
中使用? I am trying to build a List Function
that will perform a XSL Transformations and I was hoping to be able to use the Sarissa
library. 我正在尝试构建一个将执行XSL转换的
List Function
,我希望能够使用Sarissa
库。
EDIT : Please see my related question about XSL Transformations in CouchDB. 编辑 :请参阅我在CouchDB中关于XSL转换的相关问题 。
You'll need to add the source files of the library to your design document. 您需要将库的源文件添加到设计文档中。 (assuming it's a JS library) How you do that depends on many factors, plus you didn't specify how you're deploying to your CouchDB instance, so I'll just sidestep that for now.
(假设它是一个JS库)你如何做到这一点取决于很多因素,而且你没有指定你如何部署到你的CouchDB实例,所以我现在只是回避它。
The point is you can share code with list functions (among some others like map functions) as CommonJS modules . 关键是你可以将代码与list函数(在其他一些函数中,如map函数)共享为CommonJS模块 。 If you load the source file into a string that is stored in your design document, you can use the exported library via
require("lib/sarissa")
for example. 如果将源文件加载到存储在设计文档中的字符串中,则可以通过
require("lib/sarissa")
使用导出的库。
If the library is compatible with CommonJS, you can include it with: 如果库与CommonJS兼容,您可以将其包含在:
function(head, req) {
var Sarissa = require("lib/sarissa");
...
}
If not, you can include it with couchapp
precompiler: 如果没有,您可以使用
couchapp
预编译器包含它:
function(head, req) {
// !code lib/sarissa.js
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.