概要 †
javascriptのminifyをコマンドで行います。
手順 †
- uglify-jsをインストール
1
|
| npm install -g uglify-js
|
サンプル †
サンプルスクリプト全体はスクリプト/deploy.shを参照
1
2
3
4
5
6
7
8
9
10
11
|
-
|
|
|
|
|
!
| function JSOptimize() {
find "$workPath/code/skin" -type f ! -name '*.min.js' -and -name '*.js' -print0 |
while read -r -d '' orgFilePath
do
local cnvFilePath=${orgFilePath%%.js}_$DATETIME.min.js
uglifyjs "$orgFilePath" > "$cnvFilePath" || { echo "[!!ERROR!!] failed to JS optimize(minify)"; exit 1; }
find "$workPath/code" -type f -print0 |
xargs -0 sed -i "s/`basename $orgFilePath .js`\.js/`basename $cnvFilePath .min.js`\.min\.js/g" ||
{ echo "[!!ERROR!!] failed to JS optimize"; exit 1; }
done
}
|
検証時の環境 †