简体   繁体   English

如何在Compound.JS中自动加载Moment.JS?

[英]How can I autoload Moment.JS in Compound.JS?

I want Moment to be available globally, and I understand Compound is capable of auto-loading modules - so how would I use it? 我希望Moment可以在全球范围内使用,并且我了解Compound能够自动加载模块-那么我将如何使用它呢? If I include "moment" in the autoload array, how can I use it in the application? 如果我在自动加载数组中包含“ moment”,如何在应用程序中使用它?

I know there's thoughts about redoing the module loading in compound, and I know it's also not easy to find information about how to do it. 我知道有关于在复合中重做模块加载的想法,并且我知道查找有关如何执行操作的信息也不容易。

I solved it by putting a loadLibs.js in config->initializers where I load modules like so: 我通过将loadLibs.js放在config-> initializers中来解决它,我在其中加载模块,如下所示:

module.exports = function(compound) {
    compound.module1 = require('module1');
    compound.module2 = require('module2');
    //etc.
};

modules will then be available on the compound object. 模块将在复合对象上可用。 just be careful not to try to overwrite some already existing keys on the compound object. 请注意不要尝试覆盖复合对象上一些已经存在的键。 you could also put it under a namespace like compound.myApp.module 您也可以将其放在诸如compound.myApp.module之类的命名空间下

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

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