ES6 module: re-export as object

后端 未结 2 1816
温柔的废话
温柔的废话 2021-01-01 20:30

I have moduleA which exports some functions:

// moduleA.js
export function f1() {...}
export function f2() {...}

Is there any way to re-exp

相关标签:
2条回答
  • 2021-01-01 20:41

    file1.js

    export let uselessObject = {
      con1 : function () {
        console.log('from file1.js')
      }
    }
    

    file2.js

    import { uselessObject } from './file1.js'
    
    uselessObject.con2 = function(){
      console.log('from file2.js ')
    }
    
    export { uselessObject } from './file1.js'
    

    Index.js

    import { uselessObject } from './file2.js'
    uselessObject.con1()
    uselessObject.con2()
    

    Output

    from file1.js
    from file2.js
    
    0 讨论(0)
  • 2021-01-01 20:58

    The syntax is not supported yet but there is a proposal for it.

    You can use it now with Babel.js or simply do:

    import * as a from '...';
    export {a};
    
    0 讨论(0)
提交回复
热议问题