简体   繁体   English

Derby.js:将仅客户端代码拆分为多个文件

[英]Derby.js: split client-side only code into several files

I'm trying to split some client-side-only code into several files in a Derby.js project. 我试图在Derby.js项目中将一些仅客户端代码分成几个文件。 It has to be client-side only since it's interacting with the TinyMCE editor. 仅当它与TinyMCE编辑器进行交互时,它才必须是客户端。 So I tried: 所以我尝试了:

app.ready(function(model) {
    var tiny = derby.use(require('../../lib/app/TinyMCE'))
    //other client-side code
}

and put the following into lib/app/TinyMCE.js : 并将以下内容放入lib/app/TinyMCE.js

var derby = require('derby')
module.exports.decorate = 'derby'; //because before I got an 'decorate' is undefined error...
module.exports.TinyMCE = function() {
    //code
}

But now I'm getting a object is not a function error. 但是现在我得到的object is not a function错误。

Am I even on the right track? 我是否在正确的轨道上? I also considered putting the code in the public directory, but the cache-expiration of one year makes this rather inconvenient. 我也考虑过将代码放在公共目录中,但是一年的缓存过期使它相当不方便。

Also, is there really no isServer or isClient method to query? 另外,真的没有isServerisClient方法可查询吗?

Okay, I don't know whether that's a good way, but I got it working: 好的,我不知道这是否是一个好方法,但是我知道它可以工作:

module.exports = tiny
tiny.decorate = 'derby'
function tiny() {
     //code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM