Makefile结合js文件制作压缩版 [英] Makefile to combine js files and make a compressed version

查看:33
本文介绍了Makefile结合js文件制作压缩版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个基本的 makefile,将多个 js 文件组合成一个,然后执行相同的操作但压缩它们.

I am trying to write a basic makefile that combines multiple js files into a single one and then does the same but compresses them.

到目前为止,我有一个可以使压缩版本正常的.

So far I have this one that can make the compressed version fine.

# Set the source directory
srcdir = src/

# Create the list of modules
modules =   ${srcdir}core.js
            ${srcdir}sizzle.js
            ${srcdir}json2.js
            ${srcdir}ajax.js
            ${srcdir}attribute.js
            ${srcdir}content.js
            ${srcdir}cookie.js
            ${srcdir}css.js
            ${srcdir}event.js
            ${srcdir}json.js
            ${srcdir}location.js
            ${srcdir}opacity.js
            ${srcdir}ready.js
            ${srcdir}size.js
            ${srcdir}init.js

# Compress all of the modules into spark.js
spark.js: ${modules}
    java -jar yuicompressor.jar -o $@ $^

有谁知道我将如何添加一个名为 spark-dev.js 的未压缩版本?我一直在尝试使用 cat 但我没有走多远.这是我写的第一个 makefile.

Does anyone know how I would go about adding an uncompressed version called spark-dev.js? I have been trying to use cat but I didn't get very far. This is my first makefile I have ever written.

编辑我用猫试过这段代码

spark-dev.js: ${modules}
    cat $@ $^

推荐答案

你就快到了 :-) 这应该有效:

You were almost there :-) This should work:

spark-dev.js: ${modules}
    cat > $@ $^

背景:cat 的功能是(尝试)打开其命令行中列出的所有文件,并将内容转储到标准输出.<代码>>$@ 语法被 shell 理解为创建文件 $@,并将此命令的标准输出连接到它",所以现在我们最终得到 $ 的内容^ 组合成 $@.

Background: The function of cat is to (try to) open all the files listed on its command line, and dump the contents to stdout. The > $@ syntax is understood by the shell to mean "create the file $@, and connect this command's stdout to it", so now we end up with the contents of $^ combined together into $@.

这篇关于Makefile结合js文件制作压缩版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆