使用 gulp 压缩 CSS
# 安装 gulp-minify-css
模块(用于压缩 css)
npm i gulp-minify-css
1
# gulpfile.js
完整代码
const gulp = require('gulp');
const minifyCSS = require('gulp-minify-css')
// 压缩css
function compressCSS(cb){
gulp.src('css/*.css')
.pipe(minifyCSS())
.pipe(gulp.dest('dist/css'))
cb()
}
exports.compressCSS = compressCSS
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 运行查看结果
gulp compressCSS
[15:23:52] Using gulpfile D:\test\gulp\gulpfile.js
[15:23:52] Starting 'compressCSS'...
[15:23:52] Finished 'compressCSS' after 10 ms
1
2
3
4
5
2
3
4
5
上次更新: 2023/09/22, 16:54:32