Import ES6 module into global scope

前端 未结 2 1559
慢半拍i
慢半拍i 2020-12-06 10:47

TLDR: How can I make a module (imported via ES6 syntax) globally scoped (or reference an imported class inside another class)?


I\'m importing

2条回答
  •  眼角桃花
    2020-12-06 11:29

    I've done some testing and this works correctly:

    import './middleman';
    
    // './middleman.js'
    window.Example = require('./example.js').default
    // OR
    window.Example = require('./example.js').Example
    
    // './example.js'
    export function Example() {
      this.name = 'Example'
    }
    export { Example as default }
    

提交回复
热议问题