Pass options to ES6 module imports

后端 未结 7 1347
[愿得一人]
[愿得一人] 2020-11-22 04:43

Is it possible to pass options to ES6 imports?

How do you translate this:

var x = require(\'module\')(someoptions);

to ES6?

7条回答
  •  眼角桃花
    2020-11-22 05:24

    Here's my take on this question using the debug module as an example;

    On this module's npm page, you have this:

    var debug = require('debug')('http')

    In the line above, a string is passed to the module that is imported, to construct. Here's how you would do same in ES6


    import { debug as Debug } from 'debug' const debug = Debug('http');


    Hope this helps someone out there.

提交回复
热议问题