-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathgulpfile.js
126 lines (111 loc) · 2.91 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* Created by smohan on 2016/11/15.
*/
"use strict";
const gulp = require('gulp'),
sass = require('gulp-sass'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
plumber = require('gulp-plumber'),
cleanCss = require('gulp-clean-css'),
autoprefixer = require('gulp-autoprefixer'),
uglify = require('gulp-uglify'),
order = require('gulp-order'),
concat = require("gulp-concat"),
header = require('gulp-header'),
sourcemaps = require("gulp-sourcemaps"),
babel = require("gulp-babel");
const pkg = require('./package.json');
const CONFIGS = {
scss: {
lineNumbers: true,
//style : 'expanded',
sourcemap: false
},
css: {
advanced: true,
keepBreaks: false,
mediaMerging: true,
keepSpecialComments: '*'
},
js: {
mangle: true,
compress: true,
preserveComments: 'some'
}
};
gulp.task('clean', () => {
return gulp.src(['dist/', 'build/'])
.pipe(clean());
});
//编译scss文件
gulp.task('compile:css', () => {
return gulp.src('src/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions', 'Android >= 4.0'],
cascade: true,
remove: true
}))
.pipe(gulp.dest('dist/css'))
});
//编译es6文件
gulp.task('compile:js', () => {
return gulp.src('src/js/**/*.js')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel({
presets: [
['es2015', {
modules: false,
loose: true
}]
]
}))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest('dist/js'));
});
//编辑 => dist
gulp.task('compile', ['compile:js', 'compile:css']);
//banner
const Banner = [
'/*!',
' * <%= pkg.name %> v<%= pkg.version %>',
' * <%= pkg.author %>',
' * The <%= pkg.license %> License (<%= pkg.license %>)',
' * https://smohan.net/lab/smusic',
' * <%= pkg.homepage%>',
' */',
''
].join('\n');
//min css
gulp.task('build:css', () => {
return gulp.src('dist/css/smusic.css')
.pipe(cleanCss(CONFIGS.css))
.pipe(rename('smusic.min.css'))
.pipe(header(Banner, {
pkg: pkg
}))
.pipe(gulp.dest('build/'));
});
//concat && min js
gulp.task('build:js', () => {
return gulp.src('dist/js/**/*.js')
.pipe(order([
'mo.js',
'smusic.js',
]))
.pipe(concat("smusic.min.js"))
.pipe(uglify(CONFIGS.js))
.pipe(header(Banner, {
pkg: pkg
}))
.pipe(gulp.dest('build/'));
});
//min => build
gulp.task('build', ['build:js', 'build:css']);
gulp.task('watch', () => {
gulp.watch('src/js/**/*.js', ['compile:js']);
gulp.watch('src/scss/**/*.scss', ['compile:css']);
});
gulp.task('default', ['watch']);