Comparing version 1.2.1 to 1.2.2
{ | ||
"name": "amidala", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Asynchronous AMD loading of CommonJS modules (no build step)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,2 +7,4 @@ # Asynchronous CommonJS/AMD Loader | ||
AMD modules should still work (the CommonJS conversion aims to preserve that functionality). | ||
## Usage | ||
@@ -24,3 +26,3 @@ | ||
By default, the AMD loader script figures out where to load modules from by inspecting its own URL. This only works if you're loading it from a `<script>` tag in the page, otherwise you need to provide the `.url` option. | ||
By default, the AMD loader script figures out where to load modules from by inspecting its own URL. This only works if you're loading it from a `<script>` tag in the page, otherwise you need to provide the `.template` option. | ||
@@ -39,3 +41,3 @@ ### What does it do? | ||
However, using the `.alias` option it is possible to redirect modules to another location. If you write an entry `.alias` that redirects to a folder, this gives users access to all suitable files in that folder, so make sure nothing sensitive is in there (even in hidden files/folders). | ||
However, using the `.alias` option it is possible to redirect modules to another location. If you write an entry `.alias` that redirects to a folder, this gives users access to all suitable files in that folder, so make sure nothing sensitive is in there (even in hidden files). | ||
@@ -57,3 +59,3 @@ ## Options | ||
If this is not specified, then it is taken to be the root (so in the above example, `"/amidala"` would return the loader script). | ||
If this is not specified, then it is taken to be the root: | ||
@@ -69,7 +71,7 @@ ```javascript | ||
By default, the loader will guess its own URL (only works if loaded via a `<script>` element in the HTML source) and load the module using queries: | ||
By default, the loader will guess its own URL (only works if loaded via a `<script>` element in the HTML source) and use that as a base: | ||
```javascript | ||
// loader URL is "/amidala.js" | ||
// modules are loaded from /amidala.js?module=... | ||
// modules are loaded from /amidala.js/... | ||
app.use(amidala.dynamic({ | ||
@@ -116,3 +118,3 @@ loader: '/amidala.js' | ||
You can provide an array for each alias: | ||
You can provide an array for each alias, and it will attempt to resolve them in order: | ||
@@ -159,2 +161,26 @@ ```javascript | ||
If you need to resolve any relative module names, do that relative to `moduleRelativeName` instead. | ||
For example, if the main entry point for a module `some-module` is `/lib/main.js` instead of `/index.js`, then `moduleRelativeName` will point to `some-module/lib/main.js`. This allows `./other.js` to correctly resolve to `/lib/other.js`. | ||
### `.transform` | ||
This lets you provide a function that transforms the module code before it is sent. This occurs after the conversion to AMD modules. | ||
You can either return a transformed code string, or use the asynchronous callback: | ||
```javascript | ||
amidala.dynamic({ | ||
transform: function (jsCode) { | ||
return '/*AMD*/\n' + jsCode; | ||
} | ||
}); | ||
amidala.dynamic({ | ||
transform: function (jsCode, callback) { | ||
someAsyncApi(jsCode, {...}, callback); | ||
} | ||
}); | ||
``` | ||
## Enabling relative modules | ||
@@ -161,0 +187,0 @@ |
21407
194