add r.js build optimization for jade plugin
This commit is contained in:
parent
ccf59fba2a
commit
608119e8ce
@ -13,7 +13,7 @@ define(["libjs-jade-runtime", "app/utils", "jade!app/text/postbox", "jade!app/te
|
|||||||
};
|
};
|
||||||
|
|
||||||
var set = function(name, value) {
|
var set = function(name, value) {
|
||||||
globals[name] = value;
|
globals[name] = value;
|
||||||
};
|
};
|
||||||
|
|
||||||
load("postbox", tt_postbox);
|
load("postbox", tt_postbox);
|
||||||
@ -37,7 +37,7 @@ define(["libjs-jade-runtime", "app/utils", "jade!app/text/postbox", "jade!app/te
|
|||||||
"render": function(name, locals) {
|
"render": function(name, locals) {
|
||||||
var rv, t = templates[name];
|
var rv, t = templates[name];
|
||||||
if (! t) {
|
if (! t) {
|
||||||
throw "Template not found: '" + name + "'";
|
throw new Error("Template not found: '" + name + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
locals = locals || {};
|
locals = locals || {};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
({
|
({
|
||||||
baseUrl: ".",
|
baseUrl: ".",
|
||||||
mainConfigFile: 'config.js',
|
mainConfigFile: 'config.js',
|
||||||
stubModules: ['text'],
|
stubModules: ['text', 'jade'],
|
||||||
|
|
||||||
name: "components/almond/almond",
|
name: "components/almond/almond",
|
||||||
include: ['embed'],
|
include: ['embed'],
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
var requirejs = {
|
var requirejs = {
|
||||||
paths: {
|
paths: {
|
||||||
"text": "components/requirejs-text/text",
|
"text": "components/requirejs-text/text",
|
||||||
|
"jade": "lib/requirejs-jade/jade",
|
||||||
"libjs-jade": "components/jade/jade",
|
"libjs-jade": "components/jade/jade",
|
||||||
"libjs-jade-runtime": "components/jade/runtime",
|
"libjs-jade-runtime": "components/jade/runtime"
|
||||||
"jade": "lib/requirejs-jade/jade"
|
|
||||||
},
|
},
|
||||||
|
|
||||||
config: {
|
config: {
|
||||||
|
@ -1,14 +1,58 @@
|
|||||||
define(['text', 'libjs-jade'], function (text, jade) {
|
define(function() {
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
|
var jade = null,
|
||||||
|
builds = {};
|
||||||
|
|
||||||
|
var fetchText = function() {
|
||||||
|
throw new Error("Environment not supported.");
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof process !== "undefined") {
|
||||||
|
var fs = require.nodeRequire("fs");
|
||||||
|
var jade = require.nodeRequire("jade");
|
||||||
|
fetchText = function(path, callback) {
|
||||||
|
callback(fs.readFileSync(path, "utf-8"));
|
||||||
|
};
|
||||||
|
} else if ((typeof window !== "undefined" && window.navigator && window.document) || typeof importScripts !== "undefined") {
|
||||||
|
fetchText = function (url, callback) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', url, true);
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState === 4) {
|
||||||
|
callback(xhr.responseText);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.send(null);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
load: function(name, req, onLoadNative, config) {
|
|
||||||
var onload = function(content) {
|
|
||||||
onLoadNative(jade.compileClient(content));
|
|
||||||
};
|
|
||||||
|
|
||||||
text.load(name + ".jade", req, onload, config);
|
fetchText: fetchText,
|
||||||
|
|
||||||
|
load: function(name, req, onload, config) {
|
||||||
|
var path = req.toUrl(name + ".jade");
|
||||||
|
fetchText(path, function(text) {
|
||||||
|
if (jade === null) {
|
||||||
|
req(["libjs-jade"], function(jade) {
|
||||||
|
onload(jade.compileClient(text));
|
||||||
|
onload(text);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
builds[name] = jade.compileClient(text);
|
||||||
|
onload(builds[name]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
write: function() {}
|
write: function(plugin, name, write) {
|
||||||
|
if (builds.hasOwnProperty(name)) {
|
||||||
|
write("define('" + plugin + "!" + name +"', function () {" +
|
||||||
|
" var fn = " + builds[name] + ";" +
|
||||||
|
" return fn;" +
|
||||||
|
"});\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user