ES6 module syntax: is it possible to `export * as Name from …`?

前端 未结 4 1717
小蘑菇
小蘑菇 2020-12-01 23:17

See question title. I found a great reference for the forms of export available, but I have not seen what I\'m looking for.

Is it possible to do somethi

4条回答
  •  青春惊慌失措
    2020-12-01 23:56

    The proposal for this spec has merged to ecma262. If you're looking for this functionality in an environment that is running a previous JS, there's a babel plugin for it! After configuring the plugin (or if you're using ecma262 or later), you are able to run the JS in your question:

    // file: constants.js
    export const SomeConstant1 = 'yay';
    export const SomeConstant2 = 'yayayaya';
    
    // file: index.js
    export * as Constants from './constants.js';
    
    // file: component.js
    import { Constants } from './index.js';
    
    const newVar = Constants.SomeConstant1; // 'yay'
    

提交回复
热议问题