简体   繁体   中英

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? If I include "moment" in the autoload array, how can I use it in the application?

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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