2016-04-21 23:31:50 +02:00
|
|
|
var path = require('path');
|
2015-06-04 18:44:08 +02:00
|
|
|
var gulp = require('gulp');
|
2020-05-08 01:33:49 +02:00
|
|
|
var sass = require('gulp-dart-sass');
|
2020-06-03 13:06:12 +02:00
|
|
|
var postcss = require('gulp-postcss');
|
|
|
|
var autoprefixer = require('autoprefixer');
|
|
|
|
var cssnano = require('cssnano');
|
2021-01-17 03:17:41 +01:00
|
|
|
var postcssCustomProperties = require('postcss-custom-properties');
|
|
|
|
var postcssCalc = require('postcss-calc');
|
2016-04-21 23:31:50 +02:00
|
|
|
var sourcemaps = require('gulp-sourcemaps');
|
|
|
|
var size = require('gulp-size');
|
2015-06-04 18:44:08 +02:00
|
|
|
var config = require('../config');
|
|
|
|
var simpleCopyTask = require('../lib/simplyCopy');
|
2016-04-21 23:31:50 +02:00
|
|
|
var renameSrcToDest = require('../lib/rename-src-to-dest');
|
2021-09-24 21:35:01 +02:00
|
|
|
var renameSrcToDestScss = require('../lib/rename-src-to-dest-scss');
|
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 = {
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
// 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: '.'})
|
2020-06-03 13:06:12 +02:00
|
|
|
.pipe(postcss([
|
|
|
|
cssnano(cssnanoConfig),
|
|
|
|
autoprefixer(autoprefixerConfig),
|
|
|
|
]))
|
2016-04-21 23:31:50 +02:00
|
|
|
.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(); }));
|
|
|
|
|
2021-09-24 21:35:01 +02:00
|
|
|
return gulp.src(sources, {base: '.'})
|
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))
|
2020-06-03 13:06:12 +02:00
|
|
|
.pipe(postcss([
|
|
|
|
cssnano(cssnanoConfig),
|
|
|
|
autoprefixer(autoprefixerConfig),
|
2021-01-17 03:17:41 +01:00
|
|
|
postcssCustomProperties(),
|
|
|
|
postcssCalc(),
|
2020-06-03 13:06:12 +02:00
|
|
|
]))
|
2016-04-21 23:31:50 +02:00
|
|
|
.pipe(size({ title: 'Wagtail CSS' }))
|
|
|
|
.pipe(config.isProduction ? gutil.noop() : sourcemaps.write())
|
2021-09-24 21:35:01 +02:00
|
|
|
.pipe(renameSrcToDestScss())
|
|
|
|
.pipe(gulp.dest("."))
|
2015-11-03 15:36:58 +01:00
|
|
|
.on('error', gutil.log);
|
2015-06-04 18:44:08 +02:00
|
|
|
});
|
2020-04-28 22:23:15 +02:00
|
|
|
|
2020-05-08 01:33:49 +02:00
|
|
|
gulp.task('styles', gulp.series('styles:sass', 'styles:css', 'styles:assets'));
|