-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
109 lines (100 loc) · 2.72 KB
/
gulpfile.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
'use strict'
const gulp = require('gulp')
const plugins = require('gulp-load-plugins')({ pattern: ['gulp-*', 'gulp.*'] })
const argv = require('yargs').argv
const chalk = require('chalk')
const log = require('fancy-log')
const map = require('vinyl-map')
const TARGET_CSS = '__tinymce-4.css'
const TARGET_CSS_PATH = './tinymce_4/static/tinymce_4/css/'
const CSS_FILES = [
'./tinymce_4/static/tinymce_4/css/*.css',
'./tinymce_4/static/tinymce_4/css/**/*.css',
'!tinymce_4/static/tinymce_4/css/__tinymce-4.css'
]
const options = {
'development': argv.D || argv.dev || argv.develop || argv.development || false,
'production': argv.P || argv.prod || argv.production || false
}
if (!options.development && !options.production) {
options.development = true
}
const processors = [
require('postcss-import'),
require('postcss-nested'),
require('postcss-color-function'),
require('postcss-pxtorem')({
rootValue: 16,
unitPrecision: 5,
propWhiteList: ['font', 'font-size', 'line-height', 'letter-spacing'],
selectorBlackList: [],
replace: true,
mediaQuery: false,
minPixelValue: 0
}),
require('autoprefixer')({
browsers: [
'Firefox >= 3',
'Explorer >= 6',
'Opera >= 9',
'Chrome >= 15',
'Safari >= 4',
'> 1%'
],
cascade: false
}),
require('postcss-custom-properties'),
require('postcss-opacity'),
require('postcss-reporter')({
clearMessages: true
})
]
gulp.task('css', () => {
return gulp.src(CSS_FILES)
.pipe(plugins.plumber({
errorHandler: (err) => {
log(
chalk.red('gulp-css:'),
chalk.yellow(err.message),
chalk.yellow(err))
}
}))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.postcss(processors))
.pipe(plugins.concat(TARGET_CSS))
.pipe(plugins.if(options.development,
plugins.sourcemaps.write('.')))
.pipe(plugins.if(options.production,
plugins.cssnano({
colormin: true,
convertValues: true,
discardComments: { removeAll: true },
discardDuplicates: true,
discardEmpty: true,
mergeIdents: true,
mergeLonghand: true,
mergeRules: true,
minifyFontValues: true,
minifyGradients: true,
minifySelectors: true,
normalizeCharset: true,
normalizeUrl: true,
reduceTransforms: true,
zindex: false
})))
.pipe(gulp.dest(TARGET_CSS_PATH))
.pipe(plugins.filter('**/*.css'))
.pipe(map((code, filename) => {
log('CSS: ' + chalk.green(filename))
}))
})
gulp.task('watch', () => {
plugins.watch(CSS_FILES, { verbose: true },
plugins.batch((cb) => {
gulp.series('css')()
cb()
}))
})
gulp.task('default',
gulp.series('css')
)