-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
106 lines (97 loc) · 2.75 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
// 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 cleanCSS = require('gulp-clean-css');
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("css_component", function() {
gulp
.src([
// path.join(process.cwd(), "./src/theme-red.css"),
path.join(process.cwd(), "./src/**/*.less"),
])
.pipe(gulp.dest("./lib"));
console.log("###### css_component done ######");
});
gulp.task("less_component", ['css_component'],function() {
gulp
.src([
path.join(process.cwd(), "./src/index.less"),
])
.pipe(less())
.pipe(cssUglify())
.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.less"),
path.join(process.cwd(), "./dist/index.css"),
])
.pipe(less())
.pipe(concat('./dist/index.css'))
.pipe(cssUglify())
.pipe(gulp.dest("./"));
console.log("###### change_dist 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']);
// gulp.task('default',['theme_src']);