forked from hcodes/snowflakes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (85 loc) · 2.54 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
'use strict';
const
gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer'),
cssnano = require('cssnano'),
del = require('del'),
fs = require('fs'),
babel = require('rollup-plugin-babel'),
uglifyOptions = {output: {comments: /^!/}},
copyright = '/*! Snowflakes | © 2020 Denis Seleznev | MIT License | https://github.com/hcodes/snowflakes/ */\n';
function replaceStyle(tag, filename) {
return $.replace(tag, filename ? fs.readFileSync(filename, 'utf-8').replace(/'/g, '\\\'') : '');
}
function js(imagesStyle, outputFile) {
return gulp.src(['src/**/*.js'])
.pipe($.rollup({
input: 'src/js/index.js',
output: {
format: 'umd',
name: 'Snowflakes',
},
plugins: [babel()]
}))
.pipe(replaceStyle('{MAIN_STYLE}', 'dist/main.css'))
.pipe(replaceStyle('{IMAGES_STYLE}', imagesStyle))
.pipe($.replace(/^/, copyright))
.pipe($.rename(outputFile))
.pipe(gulp.dest('dist/'));
}
gulp.task('clean', function() {
return del('dist/*');
});
gulp.task('css', function() {
return gulp.src('src/less/*.less')
.pipe($.less())
.pipe(postcss([
autoprefixer(),
cssnano()
]))
.pipe(gulp.dest('dist/'));
});
gulp.task('js', function() {
return js('dist/images.css', 'snowflakes.js');
});
gulp.task('js.min', function() {
return gulp.src('dist/snowflakes.js')
.pipe($.rename('snowflakes.min.js'))
.pipe($.uglify(uglifyOptions))
.pipe(gulp.dest('dist/'));
});
gulp.task('js.light', function() {
return js('', 'snowflakes.light.js');
});
gulp.task('js.light.min', function() {
return gulp.src('dist/snowflakes.light.js')
.pipe($.rename('snowflakes.light.min.js'))
.pipe($.uglify(uglifyOptions))
.pipe(gulp.dest('dist/'));
});
gulp.task('dev-examples-copy', function() {
return gulp
.src('examples/*')
.pipe(gulp.dest('dev-examples/'));
});
gulp.task('dev-examples', function() {
return gulp
.src('dev-examples/*.html')
.pipe($.replace(/https:\/\/unpkg\.com\/magic-snowflakes\//g, '../'))
.pipe(gulp.dest('dev-examples/'));
});
gulp.task('watch', function() {
gulp.watch(['src/**/*', 'examples/**/*']);
});
gulp.task('default', gulp.series(
'clean',
'css',
'js',
'js.min',
'js.light',
'js.light.min',
'dev-examples-copy',
'dev-examples'
));