-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
loader-utils: dynamic library loading (#482)
- Loading branch information
Showing
59 changed files
with
500 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Managing Dependencies | ||
|
||
> This section is work in progress, not all options are implemented/finalized | ||
Parsers and encoders for some formats are quite complex and can be quite big in terms of code size. | ||
|
||
### Loading Dependencies from Alternate CDN | ||
|
||
By default, loaders.gl loads pre-built workers and a number of bigger external libraries from the [https://unpkg.com/](https://unpkg.com/) CDN. | ||
|
||
It is possible to specify other CDNs using `options.cdn`. | ||
|
||
Keep in mind that it is typically not sufficient to point to a server that just serves the data of the files in question. Browsers do a number of security checks on cross-origin content and requires certain response headers to be properly set, and unfortunately, error messages are not always helpful. | ||
|
||
To determine your candidate CDN service is doing what is needed, check with `curl -u <url>` and look for headers like: | ||
|
||
``` | ||
content-type: application/javascript; charset=utf-8 | ||
access-control-allow-origin: * | ||
``` | ||
|
||
### Loading Dependencies from Your Own Server | ||
|
||
By setting `options.cdn: false` and doing some extra setup, you can load dependencies from your own server. This removes the impact of a potentially flaky CDN. | ||
|
||
Options: | ||
|
||
- Load from `node_modules/@loaders.gl/<module>/dist/libs/...` | ||
- Load from a modules directory `libs/...` | ||
- Load from unique locations - `options.modules[<dependency name>]` can be set to url strings. | ||
|
||
### Bundling Dependencies | ||
|
||
It is also possible to include dependencies in your application bundle | ||
|
||
- PRO: Doesn't require copying/configuring/serving supporting modules. | ||
- CON: Increases the size of your application bundle | ||
|
||
`options.modules` will let your application `import` or `require` dependencies (thus bundling them) and supply them to loaders.gl. | ||
|
||
See each loader module for information on its dependencies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
modules/3d-tiles/src/lib/classes/helpers/tile-3d-accessor-utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
/* global __VERSION__ */ // __VERSION__ is injected by babel-plugin-version-inline | ||
|
||
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest'; | ||
|
||
const EXTENSIONS = ['basis']; | ||
|
||
export const BasisLoader = { | ||
id: 'basis', | ||
name: 'Basis', | ||
version: __VERSION__, | ||
version: VERSION, | ||
extensions: EXTENSIONS, | ||
parse: data => 'not implemented yet' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# setLoaderOptions | ||
|
||
## Usage | ||
|
||
Bundling the entire `draco3d` library: | ||
|
||
```js | ||
import draco from 'draco3d'; | ||
import {setLoaderOptions} from '@loaders.gl/core'; | ||
setLoaderOptions({ | ||
modules: { | ||
draco3d | ||
} | ||
}); | ||
``` | ||
|
||
## Functions | ||
|
||
### setLoaderOptions(options : Object) : void | ||
|
||
Merge the options with the global options | ||
|
||
## Options | ||
|
||
Top-level options | ||
|
||
| Option | Type | Default | Description | | ||
| ----------------- | ------- | --------- | ------------------------------------------------------------------------------------------------------------------------ | | ||
| `options.log` | object | `console` | By default set to a `console` wrapper. Setting log to `null` will turn off logging. | | ||
| `options.worker` | boolean | `true` | If the selected loader is equipped with a worker url (and the runtime environment supports it) parse on a worker thread. | | ||
| `options.cdn` | boolean | string | `true` | `true` loads from `unpkg.com/@loaders.gl`. `false` load from local urls. `string` alternate CDN url. | | ||
| `options.modules` | Object | - | Supply bundles modules or override local urls. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {ConsoleLog} from './loader-utils/loggers'; | ||
|
||
// TODO - document these options | ||
export const DEFAULT_LOADER_OPTIONS = { | ||
CDN: 'https://unpkg.com/@loaders.gl', | ||
worker: true, // By default, use worker if provided by loader | ||
log: new ConsoleLog(), // A probe.gl compatible (`log.log()()` syntax) that just logs to console | ||
dataType: 'arraybuffer' // TODO - explain why this option is needed for parsing | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
modules/core/src/lib/loader-utils/validate-loader-version.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {setGlobalOptions} from './loader-utils/merge-options'; | ||
|
||
// Set global loader options | ||
export function setLoaderOptions(options) { | ||
setGlobalOptions(options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.