1 | jspm can be installed and used as an API dependency in a Node project:
|
2 |
|
3 | ```
|
4 | npm install jspm
|
5 | ```
|
6 |
|
7 | ```javascript
|
8 | var jspm = require('jspm');
|
9 | jspm.install('jquery'); // etc
|
10 | ```
|
11 |
|
12 | The API is currently unstable and subject to change. The API is also lacking most jspm functions. New API suggestions or adjustments are always welcome, and PRs would be taken gladly.
|
13 |
|
14 | ## jspm API version 0.2
|
15 |
|
16 | #### setPackagePath(packagePath)
|
17 |
|
18 | Sets the directory where the jspm `package.json` file for the package being acted on is to be found.
|
19 |
|
20 | Must be run before any other API calls.
|
21 |
|
22 | ### Loader API
|
23 |
|
24 | #### import
|
25 |
|
26 | Loads a module in the jspm project in Node:
|
27 |
|
28 | ```javascript
|
29 | var jspm = require('jspm');
|
30 | jspm.setPackagePath('.');
|
31 |
|
32 | jspm.import('fs').then(function(fs) {
|
33 | console.log(fs.readFileSync('./package.json'));
|
34 | });
|
35 | ```
|
36 |
|
37 | jspm supports all Node libraries on the server and uses their Browserify equivalents in the browser.
|
38 |
|
39 | [Read more about NodeJS usage of jspm](nodejs-usage.md).
|
40 |
|
41 | #### normalize(name, parentName) -> Promise(normalized)
|
42 |
|
43 | Normalize a module name within the current jspm project.
|
44 |
|
45 | #### class Loader
|
46 |
|
47 | For more loader flexibility within the API, a new custom SystemJS loader instance can be created
|
48 | based on the current jspm environment:
|
49 |
|
50 | ```javascript
|
51 | var jspm = require('jspm');
|
52 | jspm.setPackagePath('.'); // optional
|
53 |
|
54 | var mySystem = new jspm.Loader();
|
55 |
|
56 | // can be used as any other System instance
|
57 | mySystem.normalize('moduleName').then(function(normalized) {
|
58 |
|
59 | });
|
60 | mySystem.import('moduleName').then(function(module) {
|
61 |
|
62 | });
|
63 | ```
|
64 |
|
65 | [Read more on the SystemJS API](https://github.com/systemjs/systemjs/blob/master/docs/system-api.md)
|
66 |
|
67 | ### Bundle API
|
68 |
|
69 | #### bundle(expression, fileName, options) -> Promise()
|
70 |
|
71 | ```javascript
|
72 | // jspm bundle app/main build.js --no-mangle
|
73 | var jspm = require('jspm');
|
74 | jspm.setPackagePath('.');
|
75 | jspm.bundle('app/main', 'build.js', { mangle: false }).then(function() {
|
76 | });
|
77 | ```
|
78 |
|
79 | Set the `injectConfig` option to inject the bundle tree into the configuration file.
|
80 |
|
81 | ### unbundle() -> Promise()
|
82 |
|
83 | Removes any existing `depCache` or `bundle` configuration from the configuration file.
|
84 |
|
85 | #### bundleSFX(moduleName, fileName, options) -> Promise()
|
86 |
|
87 | Creates a single self-executing bundle for a module.
|
88 |
|
89 | ##### Bundle Options
|
90 |
|
91 | Both `bundle` and `bundleSFX` support the following options:
|
92 |
|
93 | * `minify`: Use minification, defaults to false.
|
94 | * `mangle`: Use mangling with minification, defaults to true.
|
95 | * `lowResSourceMaps`: Use faster low-resolution source maps, defaults to true.
|
96 | * `sourceMaps`: Use source maps, defaults to true.
|
97 |
|
98 | #### class Builder
|
99 |
|
100 | When more build flexibility is needed, create a custom SystemJS Builder instance for the current jspm environment via:
|
101 |
|
102 | ```javascript
|
103 | var jspm = require('jspm');
|
104 | jspm.setPackagePath('.'); // optional
|
105 |
|
106 | var builder = new jspm.Builder();
|
107 |
|
108 | builder.config({ custom: 'options' });
|
109 |
|
110 | // or builder.buildStatic
|
111 | builder.bundle('app/main.js', {
|
112 | minify: true
|
113 | })
|
114 | .then(function(output) {
|
115 | // output is now an in-memory build
|
116 | // output.source
|
117 |
|
118 | // get the depCache configuration for the tree
|
119 | var depCache = builder.getDepCache(output.tree);
|
120 | });
|
121 | ```
|
122 |
|
123 | The builder will be automatically configured to have the correct jspm configuration and baseURL for the environment.
|
124 |
|
125 | [Read more on the builder API at the SystemJS builder project page](https://github.com/systemjs/builder)
|
126 |
|
127 | ### Package Manager API
|
128 |
|
129 | #### dlLoader -> Promise()
|
130 |
|
131 | Downloads the loader files if needed.
|
132 |
|
133 | #### install(name [,target] [, options]) -> Promise()
|
134 | #### install(targets [, options]) -> Promise()
|
135 | #### install(true [, options]) -> Promise()
|
136 |
|
137 | Installs the given package or packages.
|
138 |
|
139 | ```javascript
|
140 | // jspm install jquery
|
141 | jspm.install('jquery')
|
142 |
|
143 | // jspm install jquery=github:components/jquery@^2.0.0
|
144 | jspm.install('jquery', 'github:components/jquery@^2.0.0')
|
145 |
|
146 | // jspm install jquery=2
|
147 | // jspm install jquery@2
|
148 | jspm.install('jquery', '2')
|
149 |
|
150 | // jspm install jquery --force
|
151 | jspm.install('jquery', { force: true })
|
152 |
|
153 | // jspm install jquery@1.2.3 bootstrap --link
|
154 | jspm.install({ jquery: '1.2.3', 'bootstrap': true }, { link: true })
|
155 |
|
156 | // jspm install
|
157 | // reproducible install from package.json
|
158 | jspm.install(true, { lock: true })
|
159 | ```
|
160 |
|
161 | #### uninstall(name) -> Promise()
|
162 | #### uninstall(names) -> Promise()
|
163 |
|
164 | Can take a single module or array of modules to uninstall.
|
165 |
|