Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 2a30db3

Browse files
committed
Proper cssnano integration
1 parent f319aca commit 2a30db3

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

gulpconfig.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ module.exports = {
8585
, dest: build
8686
}
8787
, compiler: 'libsass' // Choose a Sass compiler: 'libsass' or 'rubysass'
88-
, autoprefixer: { browsers: ['> 3%', 'last 2 versions', 'ie 9', 'ios 6', 'android 4'] } // This tool is magic and you should use it in all your projects :)
89-
, minify: { safe: true }
88+
, cssnano: {
89+
autoprefixer: {
90+
add: true
91+
, browsers: ['> 3%', 'last 2 versions', 'ie 9', 'ios 6', 'android 4'] // This tool is magic and you should use it in all your projects :)
92+
}
93+
}
9094
, rubySass: { // Requires the Ruby implementation of Sass; run `gem install sass` if you use this; Compass is *not* included by default
9195
loadPath: ['./src/scss', bower, modules] // Adds Bower and npm directories to the load path so you can @import directly
9296
, precision: 6

gulpfile.js/tasks/styles.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,25 @@ var gulp = require('gulp')
44
, gutil = require('gulp-util')
55
, plugins = require('gulp-load-plugins')({ camelize: true })
66
, config = require('../../gulpconfig').styles
7-
, autoprefixer = require('autoprefixer')
8-
, processors = [autoprefixer(config.autoprefixer)] // Add additional PostCSS plugins to this array as needed
97
;
108

11-
// Build stylesheets from source Sass files, autoprefix, and write source maps (for debugging) with rubySass
9+
// Build stylesheets from source Sass files, post-process, and write source maps (for debugging) with rubySass
1210
gulp.task('styles-rubysass', function() {
1311
return plugins.rubySass(config.build.src, config.rubySass)
1412
.on('error', gutil.log) // Log errors instead of killing the process
15-
.pipe(plugins.postcss(processors))
16-
.pipe(plugins.cssnano(config.minify))
17-
.pipe(plugins.sourcemaps.write('./')) // No need to init; this is set in the configuration
18-
.pipe(gulp.dest(config.build.dest)); // Drops the unminified CSS file into the `build` folder
13+
.pipe(plugins.cssnano(config.cssnano)) // Post-process CSS (minify, autoprefix, etc.)
14+
.pipe(plugins.sourcemaps.write('./')) // Write an external sourcemap; no need to initialize with rubysass as this is already done in the configuration
15+
.pipe(gulp.dest(config.build.dest)); // Render the final CSS file(s) into the `build` folder
1916
});
2017

21-
// Build stylesheets from source Sass files, autoprefix, and write source maps (for debugging) with libsass
18+
// Build stylesheets from source Sass files, post-process, and write source maps (for debugging) with libsass
2219
gulp.task('styles-libsass', function() {
2320
return gulp.src(config.build.src)
24-
.pipe(plugins.sourcemaps.init())
21+
.pipe(plugins.sourcemaps.init()) // Note that sourcemaps need to be initialized with libsass
2522
.pipe(plugins.sass(config.libsass))
26-
.pipe(plugins.postcss(processors))
27-
.pipe(plugins.cssnano(config.minify))
28-
.pipe(plugins.sourcemaps.write('./')) // Writes an external sourcemap
29-
.pipe(gulp.dest(config.build.dest)); // Drops the unminified CSS file into the `build` folder
23+
.pipe(plugins.cssnano(config.cssnano))
24+
.pipe(plugins.sourcemaps.write('./'))
25+
.pipe(gulp.dest(config.build.dest));
3026
});
3127

3228
// Easily configure the Sass compiler from `/gulpconfig.js`

0 commit comments

Comments
 (0)