ES6 import equivalent of require() without exports

前端 未结 1 1386
梦毁少年i
梦毁少年i 2020-12-05 12:31

By using require(./filename) I can include and execute the code inside filename without any export defined inside filename itself.

Wha

相关标签:
1条回答
  • 2020-12-05 13:22

    The equivalent is simply:

    import "./filename";
    

    Here are some of the possible syntax variations:

    import defaultMember from "module-name";  
    
    import * as name from "module-name";  
    
    import { member } from "module-name";  
    
    import { member as alias } from "module-name";  
    
    import { member1 , member2 } from "module-name";  
    
    import { member1 , member2 as alias2 , [...] } from "module-name";  
    
    import defaultMember, { member [ , [...] ] } from "module-name";  
    
    import defaultMember, * as name from "module-name";  
    
    import "module-name";
    

    SOURCE: MDN

    0 讨论(0)
提交回复
热议问题