Last active
December 30, 2015 03:30
-
-
Save zhangtao07/28d2db7e1816f6518eb0 to your computer and use it in GitHub Desktop.
FIS构建产出替换字符串
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
//需求场景示例,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); | |
}) | |
}); | |
}] | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mark