How do changes require import with a key in ES6?
The syntax for importing an aliased module member is:
import {key as foo} from 'bar';
This is equivalent to var foo = require('bar').key;
If you want to import an element without overlaying it, the syntax is simpler:
import {foo} from 'bar';
Equivalent to:
var foo = require('bar').foo;
source to share
var foo = require('bar').key
identical var bar = require('bar'); var foo = bar.key
(otherwise than declaring the variable "bar", which is probably no longer needed).
if you export an object named "key" it will be the same in ES6 import / export.
import bar from 'bar';
var foo = bar.key;
Note This assumes a default export ( export default xxx
) as in the OP. If named export ( export foo
) is used the syntax to use is -import {foo} from 'bar'
source to share