Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #38817
| Subject | Re: Using a single module |
|---|---|
| Newsgroups | comp.lang.javascript |
| References | <67Wdnb4wtM6Kr_nCnZ2dnUU7-aPNnZ2d@westnet.com.au> <ff088a45-1c0f-4cc3-bad2-f0e841299460o@googlegroups.com> |
| From | Andrew Poulos <ap_prog@hotmail.com> |
| Date | 2020-09-20 15:27 +1000 |
| Message-ID | <44OdnYKC14DddfvCnZ2dnUU7-IXNnZ2d@westnet.com.au> (permalink) |
On 18/09/2020 9:40 pm, Julio Di Egidio wrote:
> On Friday, 18 September 2020 06:05:58 UTC+2, Andrew Poulos wrote:
>> I'm trying my first use of modules and there some concepts that escape
>> me despite goog's help.
>>
>> If I find an ES module I'd like to use I can add it to the head of the
>> page eg
>> <script type="module" src="modules/jspdf.es.min.js"></script>
>>
>> To use it in my code I need the script element that includes index.js to
>> have type="module" eg
>> <script type="module" src="scripts/index.js"></script>
>>
>> In index.js I have: import { ...
>>
>> If I have other script files referenced in my page eg
>> <script src="scripts/two.js"></script>
>>
>> and two.js wants to reference functions in index.js then it seems I need to
>> a. export the functions in index.js
>> b. add type="module" to the two.js' script element
>>
>> Then if there's another js file, third.js, that references a function in
>> index.js then I need to do the same. And so on for every other js file
>> that references function in files that are included as modules.
>>
>> So I end up with every script element having type="module" and every js
>> file exporting functions even though there's only one actual module I'd
>> like to use. Is that correct or am I missing something?
>
> Indeed, the docs as well as various articles I have opened
> do not seem to consider a mixed scenario at all: which may
> be telling.
>
> Anyway, I have found this solution, using dynamic imports:
> <https://stackoverflow.com/a/63316858>
Dang, how do you guys find these things when I spend hours searching and
find nothing?
> Another approach I have seen mentioned is to transpile the
> modules to standard JS.
Yes, I managed to find a UMD version of the module and I'm using that
instead.
> Can't tell you more, I have never tried modules in the browser...
Thanks
Andrew Poulos
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using a single module Andrew Poulos <ap_prog@hotmail.com> - 2020-09-18 14:05 +1000
Re: Using a single module Julio Di Egidio <julio@diegidio.name> - 2020-09-18 04:40 -0700
Re: Using a single module Andrew Poulos <ap_prog@hotmail.com> - 2020-09-20 15:27 +1000
Re: Using a single module Arno Welzel <usenet@arnowelzel.de> - 2020-09-20 11:27 +0200
Re: Using a single module Julio Di Egidio <julio@diegidio.name> - 2020-09-20 02:38 -0700
Re: Using a single module Julio Di Egidio <julio@diegidio.name> - 2020-09-20 02:51 -0700
Re: Using a single module "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-09-18 11:06 -0700
Re: Using a single module Andrew Poulos <ap_prog@hotmail.com> - 2020-09-20 15:27 +1000
Re: Using a single module Julio Di Egidio <julio@diegidio.name> - 2020-09-20 02:46 -0700
Re: Using a single module Arno Welzel <usenet@arnowelzel.de> - 2020-09-20 11:26 +0200
Re: Using a single module Julio Di Egidio <julio@diegidio.name> - 2020-09-20 02:42 -0700
Re: Using a single module Arno Welzel <usenet@arnowelzel.de> - 2020-09-24 19:34 +0200
Re: Using a single module Julio Di Egidio <julio@diegidio.name> - 2020-09-24 11:16 -0700
Re: Using a single module Arno Welzel <usenet@arnowelzel.de> - 2020-09-24 20:44 +0200
Re: Using a single module Julio Di Egidio <julio@diegidio.name> - 2020-09-24 11:59 -0700
Re: Using a single module Scott Sauyet <scott.sauyet@gmail.com> - 2020-09-24 19:55 -0700
Re: Using a single module Julio Di Egidio <julio@diegidio.name> - 2020-09-24 20:13 -0700
Re: Using a single module Arno Welzel <usenet@arnowelzel.de> - 2020-09-26 23:37 +0200
Re: Using a single module Scott Sauyet <scott.sauyet@gmail.com> - 2020-09-26 15:41 -0700
Re: Using a single module Jon Ribbens <jon+usenet@unequivocal.eu> - 2020-09-26 23:04 +0000
Re: Using a single module Arno Welzel <usenet@arnowelzel.de> - 2020-09-26 23:36 +0200
csiph-web