define([
"can",
"./routes",
"@loader",
"form.stache!"
], function(){
});
app.js
Names used to identify modules in the context of another module.
Current module:
Current address:
login
http://localhost/app/login/login.js
// login.js
define(["./form"], function(){
});
Importing:
./form
Normalized name:
form
Address:
http://localhost/app/form.js
Base Url:
http://localhost/app
{
"login": {
"validation": {}, // -> "login/validation"
"models": {
"user": {}
}
},
"form": {
"submission": {}
}
}
├── login/
| ├── models/
| | ├── user.js
| ├── login.js
| ├── form.js
| ├── validation.js
steal("login");
login/login
steal("./validation");
login/validation
steal("./form.js");
login/form
<script src="steal.js" data-config="config.js"></script>
<script src="node_modules/steal/steal.js"></script>
<script src="bower_components/steal/steal.js"></script>
<script src="node_modules/steal/steal.js" data-config="bower.json!bower"></script>
<script src="steal.js" config="package.json!npm"></script>
System.config({
"paths": {
"socket.io-client": "lib/packages/socket.io-client.js"
},
"meta": {
"socket.io-client": {
"format": "global"
}
},
"ext": {
"stache": "can/view/stache/system"
}
});
{
"name": "place-my-order",
"version": "0.0.0",
"system": {
"map": {
"socket.io-client": "socket.io-client/socket.io"
},
"meta": {
"socket.io-client/socket.io": {
"format": "global"
}
}
}
}
System.config({
map: {
underscore: "lodash"
}
});
{
"name": "place-my-order",
"version": "0.0.1",
"system": {
"map": {
"socket.io-client": "socket.io-client/socket.io"
}
}
}
Specify the location of a module relative to the baseURL
System.config({
paths: {
"jquery": "lib/jquery.js",
"can": "lib/can/can.js",
"can/*": "lib/can/*.js"
}
});
Additional metadata about a module.
Mostly this is for globals
System.config({
meta: {
"jquery-datepicker": {
exports: "jQuery",
deps: ["jquery"]
}
}
});
Like map, but applies to extensions.
System.config({
ext: {
stache: "can/view/stache/system"
}
});
define([
"./list.stache!"
], function(listTemplate){
...
});
https://github.com/stealjs/system-npm/blob/master/npm-crawl.js
├── node_modules/
| ├── can
| | ├── package.json (deps: jquery)
| | ├── node_module/
| ├── jquery
| | ├── package.json
| ├── bit-tabs
| | ├── package.json (deps: can)
| | ├── node_modules/
{
"name": "place-my-order",
"version": "0.0.1",
"dependencies": {
"can": "^2.3.0-pre.8",
"bit-tabs": "0.1.0-pre.1"
},
...
}
// app.js
define(["can"], function(can){
});
// system-npm
var normalize = System.normalize;
System.normalize = function(name, parentName){
var pkg = npmUtils.getPackageByName(name, parentName);
// pkg.name === "can"
// pkg.main === "can.js",
// pkg.version === "2.3.0-pre.7"
return "can@2.3.0-pre.7#can";
};
package name
package version
module path
{
"name": "place-my-order",
"version": "0.0.0",
"system": {
"meta": {
"can/util/vdom/vdom": {
"sideBundle": true
}
}
}
}
<script src="node_modules/steal/steal.js"></script>
<script>
var oldNormalize = System.normalize;
System.normalize = function(name, parentName){
return oldNormalize.apply(this, arguments).then(function(name){
if(name === "my/module") {
console.log(name, "is imported by", parentName);
}
return name;
});
};
</script>
https://gist.github.com/matthewp/1ce67c491fd3e6f18788