Created
July 8, 2014 08:25
-
-
Save hefangshi/759fbf0e07caa11bb403 to your computer and use it in GitHub Desktop.
自定义require名称
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function extJs(content){ | |
var map = fis.compile.lang; | |
var reg = /"(?:[^\\"\r\n\f]|\\[\s\S])*"|'(?:[^\\'\n\r\f]|\\[\s\S])*'|(\/\/[^\r\n\f]+|\/\*[\s\S]*?(?:\*\/|$))|\b(F_require)\s*\(\s*("(?:[^\\"\r\n\f]|\\[\s\S])*"|'(?:[^\\'\n\r\f]|\\[\s\S])*')\s*\)/g; | |
function callback(m, comment, type, value){ | |
if(type){ | |
switch (type){ | |
case 'F_require': | |
m = 'F_require(' + map.require.ld + value + map.require.rd + ')'; | |
break; | |
} | |
} | |
return m; | |
} | |
return content.replace(reg, callback); | |
} | |
fis.config.set('modules.preprocessor.js', extJs); | |
fis.config.set('modules.preprocessor.html', function(content){ | |
var map = fis.compile.lang; | |
var reg = /(<script(?:(?=\s)[\s\S]*?["'\s\w\/\-]>|>))([\s\S]*?)(?=<\/script\s*>|$)|(<style(?:(?=\s)[\s\S]*?["'\s\w\/\-]>|>))([\s\S]*?)(?=<\/style\s*>|$)|<(img|embed|audio|video|link|object|source)\s+[\s\S]*?["'\s\w\/\-](?:>|$)|<!--inline\[([^\]]+)\]-->|<!--(?!\[)([\s\S]*?)(-->|$)/ig; | |
function callback(m, $1, $2, $3, $4, $5, $6, $7, $8){ | |
if($1){//<script> | |
if(!/\s+type\s*=/i.test($1) || /\s+type\s*=\s*(['"]?)text\/javascript\1/i.test($1)) { | |
//without attrubite [type] or must be [text/javascript] | |
m = $1 + extJs($2); | |
} | |
} | |
return m; | |
} | |
return content.replace(reg, callback); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment