Can I use alias with NodeJS require function?

前端 未结 4 1335
春和景丽
春和景丽 2020-12-28 11:49

I have an ES6 module that exports two constants:

export const foo = \"foo\";
export const bar = \"bar\";

I can do the following in another

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-28 12:41

    I would say it is not possible, but an alternative would be:

    const m = require('module');
    const f = m.foo;
    const b = m.bar;
    

提交回复
热议问题