简体   繁体   English

使用Grunt编译,连接和缩小Sass文件

[英]Compile, Concatenate and Minify Sass files with Grunt

I'm building a sizable JS application using angularjs, and I'm using Grunt to process everything into a compact distribution. 我正在使用angularjs构建一个相当大的JS应用程序,我正在使用Grunt将所有内容处理成一个紧凑的发行版。 I can't figure out what to use to compile, concat and minify my .scss files into one single css file. 我无法弄清楚要使用什么来编译,连接和缩小我的.scss文件到一个单独的css文件。

My project is organized by modules, so the .scss files are scattered, rather than grouped in a single directory. 我的项目是按模块组织的,因此.scss文件是分散的,而不是分组在一个目录中。

I've looked at grunt-contrib-sass and grunt-contrib-compass, but they both seem to require you to individually specify files to compile. 我看过grunt-contrib-sass和grunt-contrib-compass,但他们似乎都要求你单独指定要编译的文件。 I'm looking for a solution that won't have to change when I add source files. 我正在寻找一种在添加源文件时无需更改的解决方案。

What Grunt plugin can I use to compile, concat and minify my sass files into a single css file? 我可以使用什么Grunt插件来编译,连接并将我的sass文件缩小为单个css文件?

I'm currently using concat and recess to concat and minify my plain css files: 我正在使用concat和凹进来连接和缩小我的普通css文件:

concat: {
  css: {
    src: ['<%= src.css %>'],
    dest: '<%= distdir %>/<%= pkg.name %>.css'
  },
},

recess: {
  min: {
    files: {
      '<%= distdir %>/<%= pkg.name %>.css': ['<%= distdir %>/<%= pkg.name %>.css']
    },
    options: {
      compress: true
    }
  }
}

I think a documentation about patterns can help you. 我认为有关模式的文档可以帮助您。

http://gruntjs.com/configuring-tasks#globbing-patterns http://gruntjs.com/configuring-tasks#globbing-patterns

sass: {                              // Task
  dist: {                            // Target
    options: {                       // Target options
      style: 'expanded'
    },
    src: 'foo/{a,b}*.sass',    // you can use some kind of regular expression
    dest: 'foo/css/
  }
}

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

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