ES6: import module from URL
2018 Update: The module loader spec is now a part of the ES Spec - what you are describing is allowed and possible with <script type="module">
in browsers and with a custom --loader
with Node.js as well as with Deno if you're into that.
The module loader spec and the import/export syntax are separate. So this is a property of the module loader (not a part of the ES spec). If you use a module loader that supports plugins like SystemJS.
Import ES6 module from http url in Typescript
Thanks to @acrazing's comment, I managed to resolve this problem. Here's how:
In a new ts file:
declare module 'https://*'
This mutes the error that Typescript compiler attempts to read type declaration.
If you want to access type declaration as a node dependency, paste this in a new ts file:
declare module 'https://cdnjs.cloudflare.com/ajax/libs/redom/3.26.0/redom.es.js' {
export * from 'redom'
}
and add redom
dependency in package.json
"dependencies": {
"redom": "3.26.0",
...
},
Then, type declaration is read from local ./node_modules
directory, VSCode recognizes the types as well.
es6 modules: import specific-functions as aName
There are no alternatives to the two ways you already mentioned. Readability is subjective, but both exporterGet()
and exporter.get()
are good choices that are common. If you explicitly want to list all the used function in the import
statement itself, you will have to give them individual aliases. Tree shaking tools will be able to handle both formats.
Related Topics
Microsoft Cdn for Jquery or Google Cdn
How to Use Redis Publish/Subscribe with Nodejs to Notify Clients When Data Values Change
How to Check If Element Has Any Children in JavaScript
Checking If Image Does Exists Using JavaScript
How to Use Optional Chaining in Node.Js 12
Change Route Params Without Reloading in Angular 2
JavaScript Triple Greater Than
Es6 Modules Implementation, How to Load a JSON File
Alert When Browser Window Closed Accidentally
How to Convert a String into a Math Operator in JavaScript
Does Awaiting a Non-Promise Have Any Detectable Effect
Why Not Always Use the Index as the Key in a Vue.Js for Loop
Event Listener for When Element Becomes Visible
How to Access Dom Elements in Electron
What Does the at Symbol (@) Do in Es6 JavaScript? (Ecmascript 2015)