-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (22 loc) · 862 Bytes
/
index.js
File metadata and controls
31 lines (22 loc) · 862 Bytes
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
var jade = require('react-jade')
, path = require('path')
, loaderUtils = require("loader-utils");
module.exports = function(source){
var transform = "var React = require('react');\n";
this.cacheable && this.cacheable();
var filepath = loaderUtils.getRemainingRequest(this).replace(/^!/, "");
var query = loaderUtils.parseQuery(this.query);
if(query.split){
var chunks = source.split(/\n*?\/\/ react: (\w+)\s*\n/);
chunks.shift();
if(!chunks.length) return single();
for(var i=0; i < chunks.length-1; i += 2){
transform += "exports['" + chunks[i] + "'] = " + jade.compile(chunks[i+1], {filename: filepath}).toString() + ";\n";
}
return transform;
}
return single();
function single(){
return transform + "module.exports= " + jade.compile(source, {filename: filepath}).toString();
}
}