I understand that we can use import {x} from “./file” and a variable x will be imported from file.js in the same directory. How is this handled if there are files of the same name with different extensions in the directory? For example, if there were file.js and file.ts in the same directory, how would import {x} from “./file” behave?
Tag: es6-modules
Resolve relative path to absolute url from ES6 module (in browser)
How to resolve relative path to absolute url in ES6 module (in browser)? For example : module1.js What would be the resolveUrl implementation? base-url.com/ may not be the web-site’s domain. It can be a repo where only sources are stored. Answer 🎉 You can now use to-absolute-url. It uses stacktrace.js under the hoods to get the caller function’s absolute path
How to dynamically execute/eval JavaScript code that contains an ES6 module / requires some dependencies?
I want my users to be able to use JavaScript as a scripting language inside my JavaScript application. In order to do so, I need to dynamically execute the source code. There seem to be two main options for dynamically executing JavaScript: a) Use eval(…) method ( or var func = new Function(…);) . b) Add a <script> node to
Does ES6 import/export need “.js” extension?
I installed chrome beta – Version 60.0.3112.24 (Official Build) beta (64-bit) In chrome://flags/ I enabled ‘Experimental Web Platform features’ (see https://jakearchibald.com/2017/es-modules-in-browsers) I then tried: where index.js has a line like: This refer to an existing file drawImage.js what I get in the console is error in If I change the export and add “.js” extension it works fine. Is this
Destructuring a default export object
Can I destructure a default export object on import? Given the following export syntax (export default) is the following import syntax valid JS? I ask because it DOES work on my system, but I’ve been told it should NOT work according to the spec. Answer Can I destructure a default export object on import? No. You can only destructure an
Re-export default in ES 6 modules
In ES6, is it possible to shorten the following code. I have an App.js file and an index.js. index.js Something like this index.js Answer If you use proposal-export-default-from Babel plugin (which is a part of stage-1 preset), you’ll be able to re-export default using the following code: For more information see the ECMAScript proposal. Another way (without this plugin) is: