简体   繁体   English

使用postcss缩小多个输入文件

[英]Minify multiple input file with postcss

I installed cssnano following these step: http://cssnano.co/guides/getting-started/ 我按照以下步骤安装了cssn​​ano: http ://cssnano.co/guides/getting-started/

Into the root of my project i ran: 我进入了我项目的根源:

npm install cssnano --save-dev

After i installed postcss-cli: 在我安装postcss-cli之后:

npm install postcss-cli --global

Finally i created postcss.config.js file following the guide: 最后,我按照指南创建了postcss.config.js文件:

module.exports = {
   plugins: [
    require('cssnano')({
        preset: 'default',
    }),
  ],
};

I was able to minify only a file. 我只能缩小一个文件。 In the roow of my project i executed: 在我的项目行中,我执行了:

postcss src/plugins/bootstrap/css/bootstrap.css > src/compiled.min.css

But i'm not able to include multiple input file (and i don't know if it's possible) as i did in gulp. 但是我无法像在gulp中那样包含多个输入文件(而且我不知道是否可能)。 When i try to run a command of this type: 当我尝试运行此类型的命令时:

postcss src/plugins/bootstrap/css/bootstrap.css src/plugins/animatecss/css/animate.css > src/compiled.min.css

There was the following error: 出现以下错误:

Input Error: Must use --dir or --replace with multiple input files

I found the solution at this question. 我找到了这个问题的解决方案。 I used gulp-concat-css to concatenate al css files into a bundle, as follows: 我使用gulp-concat-css将al css文件串联为一个包,如下所示:

  • I created a Gulpfile.js file in my project root and I concatenated file with gulp-concat-css as explained here: 我在项目根目录中创建了Gulpfile.js文件,并将文件与gulp-concat-css串联在一起,如下所述:

https://www.npmjs.com/package/gulp-concat-css https://www.npmjs.com/package/gulp-concat-css

var gulp = require('gulp');
var concatCss = require('gulp-concat-css');

gulp.task('default', function () {
  return gulp.src('cssfolder/*.css')
    .pipe(concatCss("bundle.css"))
    .pipe(gulp.dest('out/'));
});
  • In the prompt command, in the root of my project i ran: 在提示符命令中,我在项目的根目录中运行:

    gulp default gulp默认

And bundle.css (under out/ folder) was created. 并创建了bundle.css(在out /文件夹下)。

  • After i minified the bundle.css file with postcss: 在我用postcss缩小bundle.css文件后:

    postcss out/bundle.css > out/bundle.min.css postcss out / bundle.css> out / bundle.min.css

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM