压缩 javascript 的 Makefile
我想在 yui 压缩器中压缩 javascript, 如何编写 Make 文件来压缩 javascript。
因为语法很难,看不懂, 您能给我一个 Makefile 样本吗?
I want to compress javascript in yui compressor,
How to write Make file for compress javascript.
Because grammar is difficult and does not understand it,
Could you give me a sample Makefile for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 makefile 看起来像这样:
注意第二行缩进有一个制表符,而不仅仅是空格。 make 实用程序关心这一点。
code.compressed.js
是要写入的文件的名称,code.js
是要压缩的文件,compressor
是程序进行压缩。-o
标志指示输出文件,遵循编译器和类似工具的约定。 您的可能会有所不同; 检查其文档。变量
$@
是“此规则的目标”的 Makefile 简写,在本例中为code.compressed.js
。 类似地,$<
是“此规则的第一个依赖项”的缩写。 这些变量非常有用,因此您无需重复自己,也无需在文件重命名时进行重复更改。如果您有多个文件将全部压缩到一个输出文件中,则可以将它们全部放在依赖行上,然后在构建规则$^ em> 指定所有这些:
或者,如果您希望它们分别压缩,您可以编写一个模式规则并将其用于所有它们:
默认构建它看到的第一个目标,即
all< /代码> 在这种情况下。 要压缩的文件列表由
TARGET
变量的内容给出。%
是一个通配符,make 将替换它来生成匹配源文件名和目标文件名的规则。Your makefile would look something like
Note that the second line is indented with a tab character, not just spaces. The make utility cares about this.
code.compressed.js
is the name that the file should be written to,code.js
is the file to compress, andcompressor
is the program doing the compression.The
-o
flag indicates the output file, following the convention of compilers and similar tools. Yours may differ; check its documentation.The variable
$@
is Makefile shorthand for "this rule's target",code.compressed.js
in this case. Similarly,$<
is an abbreviation for "this rule's first dependency". These variables are useful so that you needn't repeat yourself, nor make duplicate changes when files get renamed.If you have multiple files that will all be compressed into a single output file, you can put them all on the dependency line, and then use the special variable
$^
in the build rule to specify all of them:Alternately, if you want them each compressed separately, you can write a pattern rule and use it for all of them:
Make defaults to building the first target that it sees, which is
all
in this case. The list of files to compress to is given by the contents of theTARGET
variable. The%
is a wildcard that make will substitute to generate rules for matching source and target file names.