-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
98 lines (91 loc) · 2.58 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
/**
* @file build mag design components
* @author dongshihao<[email protected]>
*/
'use strict';
const fs = require('fs');
const gulp = require('gulp');
const stylus = require('gulp-stylus');
const header = require('gulp-header');
const autoprefixer = require('autoprefixer-stylus');
const rimraf = require('gulp-rimraf');
const sourcemaps = require('gulp-sourcemaps');
const cleanCSS = require('gulp-clean-css');
const browserSync = require('browser-sync').create();
const rename = require('gulp-rename');
const minimist = require('minimist');
const pkg = require('./package.json');
/**
* 编译产出压缩文件头版权
*
* @type {string}
*/
const copyright = [
'/*!',
' * Mag-Design v<%=pkg.version%>',
' * Copyright 2017-<%=year%> Baidu, Inc.',
' * Licensed under MIT (https://github.com/mipengine/mip-mag-design)',
' */',
''
].join('\n');
const runTimestamp = Math.round(Date.now() / 1000);
const options = minimist(process.argv.slice(2));
const paths = {
srcBase: 'src/',
baseFile: 'src/main.styl',
src: 'src/**/*.styl',
dist: 'dist',
distModule: 'dist',
demo: 'src/**/*.html',
example: 'example',
tools: 'tools/'
};
gulp.task('clean', function () {
return gulp.src('dist/*', {
read: false
}).pipe(rimraf());
});
gulp.task('iconfont', ['clean'], function () {
return gulp
.src(['src/fonts/*'])
.pipe(gulp.dest('dist/fonts'));
});
gulp.task('build', ['iconfont'], function () {
return gulp.src(paths.baseFile)
.pipe(sourcemaps.init())
.pipe(stylus({
'paths': ['./node_modules/', './node_modules/*/', './src/base/'],
'import': ['variables', 'mixins'],
'use': [
autoprefixer({
browsers: ['iOS >= 8', 'ie >= 10', 'Android >= 4']
})
],
'include css': true
}))
.pipe(cleanCSS())
.pipe(rename('mag-design.min.css'))
.pipe(header(copyright, {
pkg: pkg,
year: new Date().getFullYear()
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.dist))
.pipe(browserSync.stream());
});
gulp.task('preview', ['build'], function () {
browserSync.init([paths.src, paths.demo], {
server: {
baseDir: './',
directory: false,
routes: {
'/': paths.example
}
},
open: false,
port: 8888,
cors: true
});
gulp.watch([paths.src], ['build']);
gulp.watch([paths.example + '/**']).on('change', browserSync.reload);
});