使用 Ant 生成代码
我想从内联代码片段和其他文件内容的混合内容生成一个文件。比如:
<target name="generate-js-function">
<concat destfile="mycode.js">
<header trimleading="yes">
// begin auto generated
var create = function() {
function createHtmlSnippet1() {
</header>
<fileset file="snippet1.js"/>
<header>
}
</header>
<header trimleading="yes">
// begin auto generated
var create = function() {
function createHtmlSnippet2() {
</header>
<fileset file="snippet2.js"/>
<header>
}
</header>
return '' + createHtmlSnippet1() + createHtmlSnippet2();
}
// end auto generated
</header>
</concat>
</target>
据我所知,只能有一个 header
/ footer
,那么正确的方法是什么?
更新:如果问题中有任何不清楚的地方 - 请询问 - 我会很乐意澄清。
I would like to generate a file from an intermixed content of inline code snippets and contents of other files. Something like:
<target name="generate-js-function">
<concat destfile="mycode.js">
<header trimleading="yes">
// begin auto generated
var create = function() {
function createHtmlSnippet1() {
</header>
<fileset file="snippet1.js"/>
<header>
}
</header>
<header trimleading="yes">
// begin auto generated
var create = function() {
function createHtmlSnippet2() {
</header>
<fileset file="snippet2.js"/>
<header>
}
</header>
return '' + createHtmlSnippet1() + createHtmlSnippet2();
}
// end auto generated
</header>
</concat>
</target>
AFAIK, there can be only one header
/ footer
, so what's the proper way to do it?
Update: if anything in the question isn't clear - please ask - I'll clarify happily.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于内联片段,您可以使用
string
资源:唯一的缺点是它不支持
trimleading
属性,但它允许您将代码内联到构建文件中。For the inline snippets you can use the
string
resource:The only downside is that it doesn't support the
trimleading
attribute, but it will allow you to have the code inline in your build file.将每个内联 JS 部分写入其自己的文件中,然后连接所有文件。
您可以使用 echo 任务从 ant 构建文件动态写入临时文件,然后连接片段文件和临时文件。
Write each inline JS portion into its own file, and concat all the files.
You can use the echo task to write to temp files dynamically from the ant build file, and then concat the snippet files and the temp files.