css - 如何使用 gulp-clean-css 编写一个新的 -min.css 文件而不是默认覆盖现有的 css 源文件?

标签 css node.js gulp minify gulp-clean-css

如何使用 gulp-clean-css 编写一个新的 -min.css 文件而不是默认覆盖现有的 CSS 源文件?

目前,我有这条线可以缩小文件。但是,它会用缩小版本覆盖原始版本。我希望它在原始文件基名的末尾创建一个扩展名为 -min.css 的新文件。

src(filePath).pipe(minifyCSS()).pipe(dest('./css/'));

我知道 npm 存储库中有一个 gulp-copy 我可以使用。我想知道是否有任何其他方法可以做到这一点。

谢谢

最佳答案

我认为如果不安装 任何 额外的 npm 包是不可能的,尽管考虑到 NodeJS 的性质,我认为这不会被认为是不合理的需要一个。

实现此目的的一种可能方法(无需 gulp-copy)是使用 gulp-renamerename 命令:

gulp.src(config.css)

    // Output the file before cleaning
    .pipe(gulp.dest(config.css))

    // Clean the file
    .pipe(cleanCss())

    // Rename with a .min suffix (e.g. app.css -> app.min.css)
    .pipe(rename({ suffix: ".min" }))

    // Output the minified CSS file
    .pipe(gulp.dest(config.css));

这将生成两个文件 - 未缩小的原始 .css 文件和缩小的 .min.css 文件。

关于css - 如何使用 gulp-clean-css 编写一个新的 -min.css 文件而不是默认覆盖现有的 css 源文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59242086/

相关文章:

node.js - 如何使用 Mongoose 获取 MongoDB 集合的大小(字节)?

javascript - 在没有 bundler 的情况下使用 Vue?

CSS3 过渡点击事件

html - 浏览器之间的差异

css - Bootstrap 3 中的流体容器

c# - 如何在 Outlook 客户端中显示 html 邮件中的图像?

javascript - Node : remove json element in json object

node.js - Firebase 存储从 Node.js 上传图像文件

angular - 在 systemjs 中捆绑是否有意义

node.js - Node Sass 找不到当前环境的绑定(bind) : Windows 64-bit with Node. js 6.x