The use case is simple: I just want to export an object with the name just as it was imported.
for example:
import React from 'react';
export React;
but this does not work. I have to write:
import React from 'react';
export const React = React;
But this is odd. What is the right way to do this?
UPDATED:
Thanks for helps and references. I have solved out my problem with many clues. I'd like to share some common cases for me and the solutions.
export imports
import d, {obj} from '...';
export {obj, d};
export {obj as name1, d as name2};
re-export all named imports
export * from '...';
export * as name1 from '...';
re-export some named imports
export {a, b as name1} from '...';
re-export default import as default export
export {default} from '...';
re-export default import as named export
export {default as name1} from '...';
You should be able to do
export {React}
and import it viaimport {React} from ./module
See https://developer.mozilla.org/en/docs/web/javascript/reference/statements/export for more information.
For my use case, I explicitly need some sort of explicit import statement so that babel can transpile my es7 code to es5.
The following results in an error
You gave us a visitor for the node type "ForAwaitStatement" but it's not a valid type
:My solution was to explicitly import the module by using
require()
:Given
./foo.js
:Then you should be able to do this:
The syntax more or less follows the commonjs module.exports pattern, where you would do this:
More here:
http://exploringjs.com/es6/ch_modules.html
I often do the following in index.js files that compose several files:
This blog entry provides some nice additional examples.
Important note
You should be aware this eslint-rule when accessing these exported imports. Basically, in another file, you shouldn't:
You should do this:
You could export imported file with such structure