这是一个很好的建议,我们将来需要做这样的事情。 感谢您提出问题。 :+1:
这是将来会添加的一件事。
它还允许用户自己添加新图标。
它还没有的唯一原因是因为我还不确定格式,而且我还在考虑将这些资产作为文件加载到 SPIFF。
谢谢你的链接!
只是为了完整性:我不久前为此任务创建了一个脚本。 它基本上是 Erick B. Tedeschi 和 spacehuhn 脚本的副本。 esp8266_deauther 的 repo 还包含用于此任务的另一个 (python) 脚本。
#!/bin/bash
#
# This script walks through the assets folder and minifys all JS, HTML, CSS and SVG files. It also generates
# the corresponding constants that are added to the data.h file on esp8266_deauther folder.
#
# <strong i="8">@Author</strong> Erick B. Tedeschi < erickbt86 [at] gmail [dot] com >
# <strong i="9">@Author</strong> Wandmalfarbe https://github.com/Wandmalfarbe
#
outputfile="$(pwd)/data_h_temp"
rm $outputfile
function minify_html_css {
file=$1
curl -X POST -s --data-urlencode "input@$file" http://html-minifier.com/raw > /tmp/converter.temp
}
function minify_js {
file=$1
curl -X POST -s --data-urlencode "input@$file" https://javascript-minifier.com/raw > /tmp/converter.temp
}
function minify_svg {
file=$1
svgo -i /Users/User/Desktop/icons/tools.svg -o - > /tmp/converter.temp
}
function ascii2hexCstyle {
file_name=$(constFileName $1)
result=$(cat /tmp/converter.temp | hexdump -ve '1/1 "0x%.2x,"')
result=$(echo $result | sed 's/,$//')
echo "const char DATA_${file_name}[] PROGMEM = {$result};"
}
function constFileName {
extension=$(echo $1 | egrep -io "(json|svg|css|js|html)$" | tr "[:lower:]" "[:upper:]")
file=$(echo $1 | sed 's/\.json//' | sed 's/\.svg//' | sed 's/\.css//' | sed 's/\.html//' | sed 's/\.js//' | sed 's/\.\///' | tr '/' '_' | tr '.' '_' | tr '-' '_' | tr "[:lower:]" "[:upper:]")
underscore="_"
echo $file$underscore$extension
}
cd assets
file_list=$(find . -type f)
for file in $file_list; do
echo "Processing: $file"
file_name=$(constFileName $file)
echo " Array Name: $file_name"
if [[ "$file" == *.min.js ]]; then
echo " JS already minified"
cat $file > /tmp/converter.temp
ascii2hexCstyle $file >> $outputfile
elif [[ "$file" == *.js ]]; then
echo " JS minify"
minify_js $file
ascii2hexCstyle $file >> $outputfile
elif [[ "$file" == *.min.css ]]; then
echo " CSS already minified"
cat $file > /tmp/converter.temp
ascii2hexCstyle $file >> $outputfile
elif [[ "$file" == *.html ]] || [[ "$file" == *.css ]]; then
echo " HTML and CSS minify"
minify_html_css $file
ascii2hexCstyle $file >> $outputfile
elif [[ "$file" == *.svg ]]; then
echo " SVG minify"
minify_svg $file
ascii2hexCstyle $file >> $outputfile
else
echo " without minifier"
cat $file > /tmp/converter.temp
ascii2hexCstyle $file >> $outputfile
fi
echo ""
sleep 1
done
我将尝试这样做,以便我们可以缩小所有嵌入的 JavaScript。
对于具有 4 MB 闪存的构建,让代码可读也是一个好主意。
哦哦,美妙的音乐在我耳边@TD-er :)