On 9. 7. 2019 19:02, Stefan Krecher wrote:
> Hey Herby,
> I created an aws-sdk.amd.json file with this content:
> {
> ?? ?? "paths": {
> ?? ?? ?? ?? "aws-sdk": "dist"
> ?? ?? }
> }
> and generated the config.js file via "grunt devel".
> In config.js I see the line
> "aws-sdk": "node_modules/aws-sdk/dist",
Seems like path mapping to me. Is this what you want (and then load
modules like 'aws-sdk/global' or similar?
One note: the fields does not need mimic the directory, it's the key you
choose, so it may as well be "aws": "dist".
If you just want to map one file, map it directly, so you can then just
load the specific .js file by the simple name.
> And I assume that everything in that file should be available in amber -
> but this doesn't seem to be the case.
Again, is it a file (dist.js)? If yes, then ok. If not, what do you
expect to load automatically?
Anyway, it is available for the _loader_ as the name -> folder / file
mapping (that's what config.js is, complete configuration of the loader,
and nothing more).
So, basically, you can do (if it is indeed mapped to a file) `require
value: #('aws-sdk') value: [ :aws | ... ]` and get the answer (two buts:
first, as I already wrote, doing it this way should be treated as
deprecated as it uses one type of loader's protocol specifically and
second, it won't work anyway, it needs the exports: clause you mentioned
below).
Any JS library must be loaded somewhere to be accessible. The best way
to do it in modern (that is, a few years already) Amber is to use
package's imports: line. That is how it is done all over Amber nowadays
(jquery wrapper does that, Helios does that with its dependencies etc.).
You instruct package that this is a dependency you need loaded before
its code runs and the system loads it for you (and if you specify it in
association style, also created package-level variable that stores the
export of that library), whatever the loader is now or will be later (at
least I'd like this to be the case).
> I created a shim-section in the aws-sdk.amd.json file:
> "aws-sdk": {
> ?? ?? ?? "exports": "AWS"
> }
Yes, that's needed as well, so that it knows the export value.
> But this didn't help either - using the developer-mode in chrome, I
> couldn't find the aws-sdk and importing AWS/ aws in the package-section
OF course, 'AWS' is not mapped to anything. You specified 'aws-sdk' name
in you .amd.json. You define the name for the module id by choosing what
you put in paths: section. Importing 'aws-sdk/aws' could work in this
case (but again, if you only need to use this file, probably map it
directly in paths as "aws": "dist/aws" and import: 'aws'->'aws').
> didn't help.
Because the lib needs to be loaded. The fact that it is in config.js
only allows for loading, but does not do the loading.
> Is the "old" way of using a library still possible? If I remember
> correctly, I just had to include the library on the html-page with
> <script src=.../> and the initialize the library inside a "<" and a ">"
Not recommended.
Remember that you want it as a dependency. For example if your backend
code is to use it. It is compiled to node, there is no <script> there.
Also, the deploy story would be complicated, `grunt deploy` would not
include it if you loaded it just in index.html directly, but it will be
if you specify it as dependency of one .js module on another (which is
what imports: compiles to, in a way).
> Regards
> Stefan
>
> Am Di., 9. Juli 2019 um 12:16??Uhr schrieb Herby Voj????k <
he...@mailbox.sk
> <mailto:
he...@mailbox.sk>>:
> ?? ??^ aws
>
> and in workspace just use MyClass publishedAws (inside the package with
> import, you can just use 'aws' variable directly; imports: defines
> 'package-level' variables in reality).
>
> Herby
>
>
https://groups.google.com/d/msgid/amber-lang/CADB_sZxPiA9f5Bj89-Y8ocg-Zcqv-o38ZwmJF0XvrzMDaM2D%3Dg%40mail.gmail.com
> <
https://groups.google.com/d/msgid/amber-lang/CADB_sZxPiA9f5Bj89-Y8ocg-Zcqv-o38ZwmJF0XvrzMDaM2D%3Dg%40mail.gmail.com?utm_medium=email&utm_source=footer>.