es6-modules

Is it possible to import modules from all files in a directory, using a wildcard?

风流意气都作罢 提交于 2019-11-25 22:48:31
问题 With ES6, I can import several exports from a file like this: import {ThingA, ThingB, ThingC} from \'lib/things\'; However, I like the organization of having one module per file. I end up with imports like this: import ThingA from \'lib/things/ThingA\'; import ThingB from \'lib/things/ThingB\'; import ThingC from \'lib/things/ThingC\'; I would love to be able to do this: import {ThingA, ThingB, ThingC} from \'lib/things/*\'; or something similar, with the understood convention that each file

Pass options to ES6 module imports

扶醉桌前 提交于 2019-11-25 22:45:12
问题 Is it possible to pass options to ES6 imports? How do you translate this: var x = require(\'module\')(someoptions); to ES6? 回答1: There is no way to do this with a single import statement, it does not allow for invocations. So you wouldn't call it directly, but you can basically do just the same what commonjs does with default exports: // module.js export default function(options) { return { // actual module } } // main.js import m from 'module'; var x = m(someoptions); Alternatively, if you

How can I use an es6 import in node? [duplicate]

落花浮王杯 提交于 2019-11-25 22:07:53
问题 This question already has answers here : Node.js - SyntaxError: Unexpected token import (11 answers) Closed 5 months ago . I\'m trying to get the hang of es6 imports in node and am trying to use the syntax provided in this example: Cheatsheet Link: https://hackernoon.com/import-export-default-require-commandjs-javascript-nodejs-es6-vs-cheatsheet-different-tutorial-example-5a321738b50f I\'m looking through the support table: http://node.green/, but was not able to find what version supports