3 ms·
You'll be able to achieve that behaviour when node also supports destructuring. import { readFile, writeFile } from 'fs'; import { clone } from 'lodash
by codecurve 11y ago
You'll be able to achieve that behaviour when node also supports destructuring.
import { readFile, writeFile } from 'fs';
import { clone } from 'lodash';
- msoad 11y agooops I forgot the braces! ok then, it's cool. I'm happy it does resolving to node_modules and all that automatically.
- pluma 11y agoIt's just syntactic sugar for `require`, mostly. The import mechanism should behave the same.
- loganfsmyth 11y agoJust a nit, but that isn't destructuring. Named import syntax has several differences, since name aliasing uses a different format and you cannot nest or provide default values.
- WalterSear 11y agoAs I understand it, that still involves importing the whole file, rather than just the part you need. If that is an issue, lodash is parted out by method, so you can do this instead: import clone from 'lodash/lang/clone'
- awalGarg 11y agoNot really. The destructuring syntax used in the imports is not the same as the standard array and object destructuring. Section 15.2.1.16 of the current stable ES6 specification specifies how the import syntax is resolved, and it doesn't use destructuring. P.S. Sorry too lazy to get a clickable link from the spec :P see http://awal.js.org/especser/#15.2.1.16 http://awal.js.org/especser/#15.2.1.16 if you really wanna read it