2016-04-21 23:31:50 +02:00
|
|
|
var path = require('path');
|
2015-06-04 18:44:08 +02:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var sass = require('gulp-sass');
|
2016-04-21 23:31:50 +02:00
|
|
|
var cssnano = require('gulp-cssnano');
|
|
|
|
var sourcemaps = require('gulp-sourcemaps');
|
|
|
|
var size = require('gulp-size');
|
2015-06-04 18:44:08 +02:00
|
|
|
var config = require('../config');
|
|
|
|
var autoprefixer = require('gulp-autoprefixer');
|
|
|
|
var simpleCopyTask = require('../lib/simplyCopy');
|
2016-01-14 16:13:10 +01:00
|
|
|
var normalizePath = require('../lib/normalize-path');
|
2016-04-21 23:31:50 +02:00
|
|
|
var renameSrcToDest = require('../lib/rename-src-to-dest');
|
2015-06-04 18:44:08 +02:00
|
|
|
var gutil = require('gulp-util');
|
|
|
|
|
|
|
|
var flatten = function(arrOfArr) {
|
|
|
|
return arrOfArr.reduce(function(flat, more) {
|
|
|
|
return flat.concat(more);
|
|
|
|
}, []);
|
|
|
|
};
|
|
|
|
|
2016-04-21 23:31:50 +02:00
|
|
|
var autoprefixerConfig = {
|
2017-12-21 10:59:28 +01:00
|
|
|
browsers: [
|
|
|
|
'Firefox ESR',
|
|
|
|
'ie 11',
|
|
|
|
'last 2 Chrome versions',
|
|
|
|
'last 2 ChromeAndroid versions',
|
|
|
|
'last 2 Edge versions',
|
|
|
|
'last 1 Firefox version',
|
|
|
|
'last 2 iOS versions',
|
|
|
|
'last 2 Safari versions',
|
|
|
|
],
|
2016-04-21 23:31:50 +02:00
|
|
|
cascade: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
var cssnanoConfig = {
|
|
|
|
discardUnused: {
|
|
|
|
fontFace: false,
|
|
|
|
},
|
2017-11-07 17:16:24 +01:00
|
|
|
zindex: false,
|
2016-04-21 23:31:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
gulp.task('styles', ['styles:sass', 'styles:css', 'styles:assets']);
|
|
|
|
|
|
|
|
// Copy all assets that are not CSS files.
|
|
|
|
gulp.task('styles:assets', simpleCopyTask('css/**/!(*.css)'));
|
2015-06-04 18:44:08 +02:00
|
|
|
|
2016-04-21 23:31:50 +02:00
|
|
|
gulp.task('styles:css', function() {
|
|
|
|
var sources = config.apps.map(function(app) {
|
|
|
|
return path.join(app.sourceFiles, app.appName, 'css/**/*.css');
|
|
|
|
});
|
2015-06-04 18:44:08 +02:00
|
|
|
|
2016-04-21 23:31:50 +02:00
|
|
|
return gulp.src(sources, {base: '.'})
|
2017-11-17 14:16:22 +01:00
|
|
|
.pipe(cssnano(cssnanoConfig))
|
2016-04-21 23:31:50 +02:00
|
|
|
.pipe(autoprefixer(autoprefixerConfig))
|
|
|
|
.pipe(renameSrcToDest())
|
|
|
|
.pipe(size({ title: 'Vendor CSS' }))
|
|
|
|
.pipe(gulp.dest('.'))
|
|
|
|
.on('error', gutil.log);
|
|
|
|
});
|
|
|
|
|
|
|
|
// For Sass files,
|
2015-06-04 18:44:08 +02:00
|
|
|
gulp.task('styles:sass', function () {
|
|
|
|
// Wagtail Sass files include each other across applications,
|
|
|
|
// e.g. wagtailimages Sass files will include wagtailadmin/sass/mixins.scss
|
|
|
|
// Thus, each app is used as an includePath.
|
|
|
|
var includePaths = flatten(config.apps.map(function(app) { return app.scssIncludePaths(); }));
|
|
|
|
|
|
|
|
// Not all files in a directory need to be compiled, so each app defines
|
|
|
|
// its own Sass files that need to be compiled.
|
|
|
|
var sources = flatten(config.apps.map(function(app) { return app.scssSources(); }));
|
|
|
|
|
|
|
|
return gulp.src(sources)
|
2016-04-21 23:31:50 +02:00
|
|
|
.pipe(config.isProduction ? gutil.noop() : sourcemaps.init())
|
2015-06-04 18:44:08 +02:00
|
|
|
.pipe(sass({
|
|
|
|
errLogToConsole: true,
|
|
|
|
includePaths: includePaths,
|
|
|
|
outputStyle: 'expanded'
|
2016-02-05 02:26:35 +01:00
|
|
|
}).on('error', sass.logError))
|
2017-11-17 14:16:22 +01:00
|
|
|
.pipe(cssnano(cssnanoConfig))
|
2016-04-21 23:31:50 +02:00
|
|
|
.pipe(autoprefixer(autoprefixerConfig))
|
|
|
|
.pipe(size({ title: 'Wagtail CSS' }))
|
|
|
|
.pipe(config.isProduction ? gutil.noop() : sourcemaps.write())
|
|
|
|
.pipe(gulp.dest(function (file) {
|
2015-06-04 18:44:08 +02:00
|
|
|
// e.g. wagtailadmin/scss/core.scss -> wagtailadmin/css/core.css
|
|
|
|
// Changing the suffix is done by Sass automatically
|
2016-01-14 16:13:10 +01:00
|
|
|
return normalizePath(file.base)
|
2015-06-04 18:44:08 +02:00
|
|
|
.replace(
|
2016-01-14 16:13:10 +01:00
|
|
|
'/' + config.srcDir + '/',
|
2015-06-04 18:44:08 +02:00
|
|
|
'/' + config.destDir + '/'
|
|
|
|
)
|
|
|
|
.replace('/scss/', '/css/');
|
|
|
|
}))
|
2015-11-03 15:36:58 +01:00
|
|
|
.on('error', gutil.log);
|
2015-06-04 18:44:08 +02:00
|
|
|
});
|