-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
99 lines (86 loc) · 2.26 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('autoprefixer');
var babel = require('gulp-babel');
var uglify = require('gulp-uglify');
var del = require('del');
var sourcemaps = require('gulp-sourcemaps');
var rename = require('gulp-rename');
var cssnano = require('cssnano');
var postcss = require('gulp-postcss');
var path = require('path');
var merge = require('merge-stream');
var clone = require('gulp-clone');
var paths = {
styles: {
src: 'src/lazyembed.scss',
dest: 'dist'
},
scripts: {
src: 'src/lazyembed.js',
dest: 'dist'
}
};
gulp.task('clean:styles', function() {
return del(path.join(paths.styles.dest, '**/*.css'), {
force: true
});
});
gulp.task('clean:scripts', function() {
return del(path.join(paths.scripts.dest, '**/*.js'), {
force: true
});
});
gulp.task('build:styles', ['clean:styles'], function() {
var source = gulp.src(paths.styles.src)
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded'
}))
.pipe(postcss([
autoprefixer()
]));
var styles = source.pipe(clone())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.styles.dest));
var minified = source.pipe(clone())
.pipe(rename({
suffix: '.min'
}))
.pipe(postcss([
cssnano()
]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.styles.dest));
return merge(styles, minified);
});
gulp.task('build:scripts', ['clean:scripts'], function() {
var source = gulp.src(paths.scripts.src)
.pipe(sourcemaps.init())
.pipe(babel({
presets: [
[
'env',
{
modules: false
}
]
],
plugins: [
'transform-es2015-modules-strip'
]
}));
var scripts = source.pipe(clone())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.scripts.dest));
var minified = source.pipe(clone())
.pipe(rename({
suffix: '.min'
}))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.scripts.dest));
return merge(scripts, minified);
});
gulp.task('build', ['build:styles', 'build:scripts']);
gulp.task('default', ['build']);