Skip to content

Instantly share code, notes, and snippets.

@zhangtao07
Last active December 30, 2015 03:30
Show Gist options
  • Save zhangtao07/28d2db7e1816f6518eb0 to your computer and use it in GitHub Desktop.
Save zhangtao07/28d2db7e1816f6518eb0 to your computer and use it in GitHub Desktop.
FIS构建产出替换字符串
//需求场景示例,FIS 纯前端项目,不使用前端模板,通过inline共用同样的头部区块,但希望构建后动态替换里面的各个页面title等
//注意如果已经有使用prepckager处理器,按先后顺序添加到数组中
fis.config.merge({
modules: {
prepackager: [function(ret, conf, settings, opt){
//需要替换的字符串,支持正则。
//配置方式字符串|处理
var settings = {
'/a.html': {
'#TITLE#': 'page a'
},
'/b.html': {
'#TITLE#': 'page b'
},
'/layout/c.html': {
'#TITLE#': 'page c'
}
};
fis.util.map(settings, function(filepath, config){
// 执行规则替换
fis.util.map(config, function(key, str){
var reg, arr = key.split('|');
reg = new RegExp(arr[0], arr[1]);
ret.src[filepath]._content = ret.src[filepath]._content.replace(reg, str);
})
});
}]
}
})
@yanhaijing
Copy link

mark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment