On-demand require()

前端 未结 2 1534
迷失自我
迷失自我 2021-01-22 08:22

Say I create a library in ./libname which contains one main file: main.js and multiple optional library files which are occasionally used with the main

2条回答
  •  迷失自我
    2021-01-22 08:57

    Looks like the only way is to use getters. In short, like this:

    exports = {
        MainClass : require('main.js').MainClass,
        get a(){ return require('./a.js'); },
        get b(){ return require('./a.js'); }
    }
    

提交回复
热议问题