-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcss-build.js
More file actions
79 lines (67 loc) · 1.79 KB
/
css-build.js
File metadata and controls
79 lines (67 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/** plugin builder for requirejs optimization
*/
define(function() {
var fs = require.nodeRequire('fs');
function loadfile (url, callback) {
var file = fs.readFileSync(url, 'utf8');
//Remove BOM (Byte Mark Order) from utf8 files if it is there.
if (file.indexOf('\uFEFF') === 0) {
file = file.substring(1);
}
callback(file);
};
function strip (content) {
return content.replace(/[\n]/g," ")
.replace(/[\t]/g," ");
}
var buildMap = {};
var writeonce = false;
var loader =
{
load: function (name, require, load, config) {
//console.log('css-build: load: '+name);
load(true);
loadfile(config.baseUrl+name,function(F){
buildMap[name]=strip(F);
});
},
write: function (pluginName, moduleName, write, config) {
if( !writeonce)
{
writeonce=true;
write(
"define('"+pluginName+"-embed', function()\n{\n"+
"\tfunction embed_css(content)\n"+
"\t{\n"+
"\t\tvar head = document.getElementsByTagName('head')[0],\n"+
"\t\tstyle = document.createElement('style'),\n"+
"\t\trules = document.createTextNode(content);\n"+
"\t\tstyle.type = 'text/css';\n"+
"\t\tif(style.styleSheet)\n"+
"\t\t\tstyle.styleSheet.cssText = rules.nodeValue;\n"+
"\t\telse style.appendChild(rules);\n"+
"\t\t\thead.appendChild(style);\n"+
"\t}\n"+
"\treturn embed_css;\n"+
"});\n"
);
}
write(
"define('"+pluginName+'!'+moduleName+"', ['"+pluginName+"-embed'], \n"+
"function(embed)\n{\n"+
"\tembed(\n\t'"+buildMap[moduleName]+"'\n\t);\n"+
"\treturn true;\n"+
"});\n"
);
},
writeFile: function (pluginName, moduleName, write)
{
//console.log('css-build: writeFile');
},
onLayerEnd: function (write, data)
{
//console.log('css-build: onLayerEnd');
}
};
return loader;
});