网站首页 文章专栏 使用cleancss配合powershell合并压缩css
使用cleancss配合powershell合并压缩css
发布 作者:被打断de狗腿 浏览量:281
使用cleancss配合powershell合并压缩css,有新的css,只需要添加进数组就好了。

先从npm安装cleancss

npm install clean-css-cli -g

再写powershell脚本。 脚本思路就是定义css文件所在位置的数组, 遍历该数组,判断每个css文件是否存在,再将css文件路径合并成cleancss的参数,再从powershell中执行。

$location = Get-Location
$path = $location.Path
[System.Console]::WriteLine($path)
[string[]]$cssPaths = 
    "./core/lib/layui/css/layui.css",
    "./core/lib/aplayer/APlayer.min.css",
    "./core/css/site.css",
    "./core/css/site-dark.css",
    "./core/css/nprogress.min.css",
    "./core/font-awesome/css/font-awesome.css",
    "./library/prism/prism.css",
    "./core/lib/tocbot/tocbot.css",
    "./core/lib/sakura-js/sakura.min.css",
    "./core/lib/photoswipe/photoswipe.css",
    "./core/lib/photoswipe/default-skin/default-skin.css",
    "./fonts/chinese-font.css",
    "./core/css/friends.css",
    "./core/css/comment.css",
    "./core/css/steam.css",
    "./core/css/mumble.css",
    "./core/css/markdown.css"

foreach($item in $cssPaths){
    #$newCssPath = $item.Replace("./", "").Replace("/", "\");
    #$filePath = [System.IO.Path]::Combine($path,$newCssPath)
    $filePath = [System.IO.Path]::Combine($path,$item)
    if(![System.IO.File]::Exists($filePath)){
        #[System.Console]::WriteLine()
        Write-Host "$filePath file not exists" -ForegroundColor red
        return;
    }
}

$inputParameters = [System.String]::Join(" ",$cssPaths)

#Write-Host $inputParameters

#cleancss -o ./core/css/global.min.css $inputParameters --with-rebase

$execute = "cleancss -o ./core/css/global.min.css $inputParameters --with-rebase --debug"

Invoke-Expression $execute
loading