-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
128 lines (118 loc) · 3.47 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
127
// dependency
var colors = require("colors/safe");
var path = require("path");
var shelljs = require("shelljs");
// gulp & gulp plugin
var gulp = require("gulp");
var babel = require("gulp-babel");
var sass = require('gulp-sass')
// var less = require("gulp-less");
var es3ify = require("gulp-es3ify");
var concat = require('gulp-concat');
var cssUglify = require('gulp-minify-css');
colors.setTheme({
silly: 'rainbow',
input: 'grey',
verbose: 'cyan',
prompt: 'grey',
info: 'green',
data: 'grey',
help: 'cyan',
warn: 'yellow',
debug: 'blue',
error: 'red'
});
var getFromCwd = function() {
var args = [].slice.call(arguments, 0);
args.unshift(process.cwd());
return path.join.apply(path, args);
};
gulp.task("pack_lib2", function(cb) {
console.log(colors.info("###### pack_lib2 start ######"));
gulp
.src([
path.join(process.cwd(), "./src/*.js"),
// path.join(process.cwd(), "./js/**/*.jsx")
])
.pipe(
babel({
presets: ["react", "es2015-ie", "stage-1"].map(function(item) {
return require.resolve("babel-preset-" + item);
}),
plugins: [
// "transform-object-assign",
"add-module-exports",
"transform-object-entries",
"transform-object-rest-spread",
'transform-class-properties'
].map(function(item) {
return require.resolve("babel-plugin-" + item);
})
})
)
.pipe(es3ify())
.pipe(gulp.dest("lib/"))
.on("end", function() {
console.log(colors.info("###### pack_lib2 done ######"));
cb();
});
});
gulp.task("move_style", function() {
gulp
.src([
path.join(process.cwd(), "./src/theme-red.less"),
path.join(process.cwd(), "./src/theme-red.scss"),
path.join(process.cwd(), "./src/index.less"),
path.join(process.cwd(), "./src/index.scss"),
path.join(process.cwd(), "./src/tree.less"),
])
.pipe(gulp.dest("./lib"));
console.log("###### move_style done ######");
});
gulp.task("css_minify", function() {
// gulp
// .src([
// path.join(process.cwd(), "./src/theme-red.css"),
// ])
// // .pipe(cleanCSS())
// .pipe(gulp.dest("./lib"));
// console.log("###### css_minify done ######");
});
gulp.task("less_component",['move_style','css_minify'], function() {
gulp
.src([
path.join(process.cwd(), "./src/index.scss"),
])
.pipe(sass())
.pipe(cssUglify())
// .pipe(cleanCSS())
.pipe(gulp.dest("./lib"));
console.log("###### less_component done ######");
});
//将lib下的index.css合并dist下的index.css生成完成的index.css
gulp.task("change_dist",["less_component"], function() {
gulp.src([
path.join(process.cwd(), "./src/index.scss"),
path.join(process.cwd(), "./dist/index.css"),
])
.pipe(sass())
.pipe(concat('./dist/index.css'))
.pipe(cssUglify())
.pipe(gulp.dest("./"))
console.log("###### change_dist done ######");
});
gulp.task("font-dist",["change_dist"], function () {
gulp.src('./src/font/*.{eot,svg,ttf,woff}')
.pipe(gulp.dest('./dist/font'));
console.log("###### font-dist done ######");
})
gulp.task("font-lib",["change_dist"], function () {
gulp.src('./src/font/*.{eot,svg,ttf,woff}')
.pipe(gulp.dest('./lib/font'));
console.log("###### font-lib done ######");
})
gulp.task("clean_lib2", function() {
return shelljs.rm("-rf", getFromCwd("lib"));
});
gulp.task("lib2", ["clean_lib2","pack_lib2"], function() {});
gulp.task('default',['lib2', 'change_dist', 'font-dist', 'font-lib']);