qooxdoo / qooxdoo-compiler

Compiler for Qooxdoo, 100% javascript
MIT License
36 stars 23 forks source link

Using external libraries #79

Closed johnspackman closed 5 years ago

johnspackman commented 6 years ago

From @mbgonicus on September 20, 2017 15:14

Hi, this is more a question than an issue.

What is the intended way to use a 3rd party library? So I got a single js file that exposes a global variable that I like to use somewhere in my qx code.

I know about the contribs, but that requires to create a Manifest.json for each library.

Then there is also qx.util.DynamicScriptLoader to load something at runtime, but that is asynchronous which must be respected by any code that uses the library.

So I am looking for an easy way to include external libraries at compile-time. Is there a way to do it?

Copied from original issue: qooxdoo/qooxdoo-cli#16

johnspackman commented 6 years ago

If you're using qooxdoo-compiler, you can add them to your Manifest.json, either in your application or in a contrib:

provides: { /* ... snip ... */ },
externalResources: {
   script: [ "myapp/thirdparty.js" ],
   css: [ "myapp/thirdparty.css" ]
}

This format is going to change slightly fairly soon because it does not support separating "build" from "source" compilation.

The generator has support for add-script and add-css keys, which are documented here: http://www.qooxdoo.org/5.0.2/pages/tool/generator/generator_config_ref.html

johnspackman commented 6 years ago

From @mbgonicus on September 21, 2017 6:32

All right, thank you again!

I'm using qooxdoo-compiler and got it working. Small caveat: The files referenced in "externalResources" must be in the source/resource folder.

I think this should be documented somewhere and I'm willing to provide a pr for the docs. But if it's going to change soon, it's obviously better to wait...

johnspackman commented 6 years ago

ah yes, sorry I forgot about the resources bit :) !

johnspackman commented 6 years ago

From @cajus on December 1, 2017 8:37

@johnspackman what if I want to add a CDN based script?

johnspackman commented 6 years ago

ah - it won't work, but it should just accept a URL - reopening

johnspackman commented 6 years ago

From @cajus on December 1, 2017 9:14

If asset accepts the URL, I can make a PR for that.

johnspackman commented 6 years ago

Yes please 👍

Do you mean in Application.getAssetUris Application.js? That should not return external URLs (it should only return the <library namespace>:<library uri> style), just skip those paths that are external URLs. Then Target.js needs to handle URIs differently too.

Finally, app/loader-browser.tmpl.js will need probably need some work

johnspackman commented 6 years ago

From @mbgonicus on December 18, 2017 15:30

There's another aspect I came across regarding external js files.

Let's say we got an application foo that uses a qx contrib bar. bar has a js file bar/source/resource/bar/baz.js that I want to load. I add the following lines to the Manifest of bar:

"externalResources" : {
    "script": [ "bar/baz.js" ]
}

After compiling and loading in the browser, the browser tries to fetch ../resources/bar/baz.js. But the file is available at ../resources/foo/js/baz.js, leading to to the following change in bar/Manifest.json:

"externalResources" : {
    "script": [ "foo/js/baz.js" ]
}

Thus, I must use the application's name space in a contrib when it provides a js file.

johnspackman commented 6 years ago

I guess this needs a bit of a revamp (thanks for the feedback 👍 )

cboulanger commented 5 years ago

@johnspackman Is this still valid - seems outdated.

johnspackman commented 5 years ago

Using the library classname as a prefix to the resources is correct IMHO because it allows an application to refer to the resources in libraries; that and external URLs are fixed in the next PR