使用 grunt-exec 的新行的奇怪行为
Weird Behaviour with New Lines Using grunt-exec
我正在使用 ImageMagick 和 grunt-exec 为我正在使用 ImageMagick documentation 中找到的命令的网站生成一个网站图标。
convert image.png -bordercolor white -border 0 \
\( -clone 0 -resize 16x16 \) \
\( -clone 0 -resize 32x32 \) \
\( -clone 0 -resize 48x48 \) \
\( -clone 0 -resize 64x64 \) \
-delete 0 -alpha off -colors 256 favicon.ico
但是我遇到了一些换行符问题,我认为部分原因是我不完全理解我应该如何处理换行符。
在我的 Gruntfile.js
中,我目前没有使用换行符,它按预期工作。请注意,我必须删除所有换行符并双重转义括号,因为显然 grunt-exec 在执行之前解析了字符串。
exec: {
favicon: 'convert _favicon.svg -bordercolor white -border 0 \( -clone 0 -resize 16x16 \) \( -clone 0 -resize 32x32 \) \( -clone 0 -resize 48x48 \) \( -clone 0 -resize 64x64 \) -delete 0 -alpha off -colors 256 favicon.ico'
}
就像我说的,我现在可以使用它,但是我希望能够使用换行符来提高可读性,也因为我想完全理解发生了什么在这。到目前为止,我已经尝试添加一个额外的 \
并将所有内容保持不变,用 \n
或 \n
替换新行并将所有内容放在同一行但没有运气。
试试这个:
exec: {
favicon: 'convert _favicon.svg -bordercolor white -border 0 "( -clone 0 -resize 16x16 )" "( -clone 0 -resize 32x32 )" "( -clone 0 -resize 48x48 )" "( -clone 0 -resize 64x64 )" -delete 0 -alpha off -colors 256 favicon.ico'
}
我一直在寻找的解决方案原来是使用 \n\
换行,如下所示:
convert image.png -bordercolor white -border 0 \n\
\( -clone 0 -resize 16x16 \) \n\
\( -clone 0 -resize 32x32 \) \n\
\( -clone 0 -resize 48x48 \) \n\
\( -clone 0 -resize 64x64 \) \n\
-delete 0 -alpha off -colors 256 favicon.ico
我正在使用 ImageMagick 和 grunt-exec 为我正在使用 ImageMagick documentation 中找到的命令的网站生成一个网站图标。
convert image.png -bordercolor white -border 0 \
\( -clone 0 -resize 16x16 \) \
\( -clone 0 -resize 32x32 \) \
\( -clone 0 -resize 48x48 \) \
\( -clone 0 -resize 64x64 \) \
-delete 0 -alpha off -colors 256 favicon.ico
但是我遇到了一些换行符问题,我认为部分原因是我不完全理解我应该如何处理换行符。
在我的 Gruntfile.js
中,我目前没有使用换行符,它按预期工作。请注意,我必须删除所有换行符并双重转义括号,因为显然 grunt-exec 在执行之前解析了字符串。
exec: {
favicon: 'convert _favicon.svg -bordercolor white -border 0 \( -clone 0 -resize 16x16 \) \( -clone 0 -resize 32x32 \) \( -clone 0 -resize 48x48 \) \( -clone 0 -resize 64x64 \) -delete 0 -alpha off -colors 256 favicon.ico'
}
就像我说的,我现在可以使用它,但是我希望能够使用换行符来提高可读性,也因为我想完全理解发生了什么在这。到目前为止,我已经尝试添加一个额外的 \
并将所有内容保持不变,用 \n
或 \n
替换新行并将所有内容放在同一行但没有运气。
试试这个:
exec: {
favicon: 'convert _favicon.svg -bordercolor white -border 0 "( -clone 0 -resize 16x16 )" "( -clone 0 -resize 32x32 )" "( -clone 0 -resize 48x48 )" "( -clone 0 -resize 64x64 )" -delete 0 -alpha off -colors 256 favicon.ico'
}
我一直在寻找的解决方案原来是使用 \n\
换行,如下所示:
convert image.png -bordercolor white -border 0 \n\
\( -clone 0 -resize 16x16 \) \n\
\( -clone 0 -resize 32x32 \) \n\
\( -clone 0 -resize 48x48 \) \n\
\( -clone 0 -resize 64x64 \) \n\
-delete 0 -alpha off -colors 256 favicon.ico