-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.babel.js
125 lines (110 loc) · 3.49 KB
/
gulpfile.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
'use strict';
// This gulpfile makes use of new JavaScript features.
// Babel handles this without us having to do anything. It just works.
// You can read more about the new JavaScript features here:
// https://babeljs.io/docs/learn-es2015/
import gulp from 'gulp';
import gutil from 'gulp-util';
import del from 'del';
import runSequence from 'run-sequence';
import autoprefixer from 'autoprefixer';
import mqpacker from 'css-mqpacker';
import cssnano from 'cssnano';
import postcssImport from 'postcss-import';
import postcssEach from 'postcss-each';
import postcssApply from 'postcss-apply';
import postcssSimpleVars from 'postcss-simple-vars';
import postcssCustomMedia from 'postcss-custom-media';
import postcssCustomSelectors from 'postcss-custom-selectors';
import postcssNested from 'postcss-Nested';
import postcssCssVariables from 'postcss-css-variables';
import postcssSelectorNot from 'postcss-selector-not';
import postcssCalc from 'postcss-calc';
import postcssLogicalProps from 'postcss-logical-props';
import postcssFlexbugsFixes from 'postcss-flexbugs-fixes';
import postcssReporter from 'postcss-reporter';
import postcssColor from 'postcss-color-function';
import gulpLoadPlugins from 'gulp-load-plugins';
const $ = gulpLoadPlugins();
const AUTOPREFIXER_BROWSERS = ['last 2 versions'];
gulp.task('lint-css', function lintCSS() {
const gulpStylelint = require('gulp-stylelint');
return gulp
.src('src/css/**/*.css')
.pipe(gulpStylelint({
reporters: [
{formatter: 'string', console: true}
]
}));
});
// Compile everything and test
gulp.task('styles', () => {
const PROCESSORS = [
postcssImport({ glob: true }),
postcssEach,
postcssApply,
postcssSimpleVars,
postcssCustomMedia,
postcssCustomSelectors,
postcssNested,
postcssCssVariables({
preserve: 'computed'
}),
postcssSelectorNot,
postcssCalc,
postcssColor,
postcssLogicalProps,
postcssFlexbugsFixes,
autoprefixer({browsers: AUTOPREFIXER_BROWSERS}),
mqpacker,
cssnano,
postcssReporter({clearMessages: true})
];
// For best performance, don't add Sass partials to `gulp.src`
return gulp.src(['src/css/*.css'])
.pipe($.sourcemaps.init())
.pipe($.postcss(PROCESSORS)).on('error', gutil.log)
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest('resources/public/css'));
});
// Compile CSS
gulp.task('dist', () => {
const PROCESSORS = [
postcssImport({ glob: true }),
postcssEach,
postcssApply,
postcssSimpleVars,
postcssCustomMedia,
postcssCustomSelectors,
postcssNested,
postcssCssVariables,
postcssSelectorNot,
postcssCalc,
postcssColor,
postcssLogicalProps,
postcssFlexbugsFixes,
autoprefixer({browsers: AUTOPREFIXER_BROWSERS}),
mqpacker,
cssnano,
postcssReporter({clearMessages: true})
];
return gulp.src(['src/css/*.css'])
.pipe($.postcss(PROCESSORS)).on('error', gutil.log)
.pipe(gulp.dest('dist'));
})
// Clean output directory
gulp.task('clean', () => del(['.tmp', 'resources/public/*', '!resources/public/.git', '!resources/public/js'], {dot: true}));
// Watch files for changes & recompile
gulp.task('watch', ['styles'], () => {
gulp.watch(['src/css/**/*.css'], ['styles']);
});
// Build production files, the default task
gulp.task('default', cb =>
runSequence(
'styles',
cb
)
);
// Load custom tasks from the `tasks` directory
// Run: `npm install --save-dev require-dir` from the command-line
// try { require('require-dir')('tasks'); } catch (err) { console.error(err); }