功能介绍:如图 操作是 把 project-2.0 文件夹下的shopify文件夹 内容复制到 dist文件夹里面 然后 在dist文件夹里面找到assets遍历该文件夹的js,css文件 进行压缩, 当然也可以修改文件名字 语法 ${file/.js/.min.js} 把 test.js 压缩为 test.min.js 简单实用
- webpack 安装 压缩插件
npm install -D uglify-js
npm install -D uglifycss
2. 新建minify.sh 如上图图片
3. 当前文件夹路径下执行 bash ./minify.sh
# 获取当前工作目录的绝对路径
CURRENT_DIR=$(pwd)
# 设置相对路径 项目名称
RELATIVE_PATH="/project-2.0/"
# 组合成完整的本地绝对路径
BASE_PATH="${CURRENT_DIR}/"
# 修改路径
rm -r "${BASE_PATH}dist/"
echo "===removed dist folder==="
cp -r "${BASE_PATH}shopify/" "${BASE_PATH}dist/"
echo "===copied shopify folder to dist folder==="
for file in "${BASE_PATH}dist/assets/"*.js; do
if [[ $file == *".min.js" ]]; then
echo "$file" ========= is already minified
else
uglifyjs "$file" -o "$file"
echo uglifyjs minified: "$file"
fi
done
for file in "${BASE_PATH}dist/assets/"*.css; do
if [[ $file == *".min.css" ]]; then
echo "$file" ========= is already minified
else
uglifycss "$file" --output "$file"
echo uglifycss minified: "$file"
fi
done
echo "===minified js files==="