-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
154 lines (131 loc) · 3.41 KB
/
gulpfile.babel.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import gulp, {
series,
parallel
} from 'gulp'
import glob from 'glob'
import del from 'del'
import rename from 'gulp-rename'
import rollupConfig from './rollup.config.js'
import uglify from 'gulp-uglify'
import csso from 'gulp-csso'
import jdtomk from 'jsdoc-to-markdown'
import colors from 'colors'
import {
rollup
} from 'rollup'
import {
exec
} from 'child_process'
import fs from 'fs'
let buildTasks = [];
let env = process.env.NODE_ENV;
let name = 'bee'
let dist = './dist'
gulp.task('clear', (cb) => {
del.sync([dist]);
cb()
});
// 打包完整 bee.js 和 bee.css
gulp.task('build-dev', series('clear', async function () {
console.log('build dev...........');
delete rollupConfig.output
let bundle = await rollup(rollupConfig);
for (let t of ['cjs', 'umd', 'iife']) {
var n = '',
fileName;
switch (t) {
case 'cjs':
n = '.commonjs';
break;
case 'umd':
n = '';
break;
default:
n = `.${t}`;
}
fileName = `${dist}/${name + n}.js`
await bundle.write({
file: fileName,
format: t,
name: 'Bee',
exports: 'named',
sourceMap: true,
globals: {
vue: 'Vue'
}
})
console.log(fileName.green)
}
}))
// 压缩 bee.js 到 bee.min.js
gulp.task('compress', series('build-dev', () => {
return gulp.src([`${dist}/${name}.js`, `${dist}/${name}.commonjs.js`, `${dist}/${name}.iife.js`])
.pipe(uglify({
sourceMap: true
}))
.pipe(rename({
dirname: './',
suffix: '.min'
}))
.pipe(gulp.dest(dist))
}))
// 压缩css
gulp.task('cssmin', () => {
return gulp.src(`${dist}/${name}.css`)
.pipe(csso({
sourceMap: true
}))
.pipe(rename({
dirname: './',
basename: `${name}.min`
}))
.pipe(gulp.dest(dist))
})
// 生成文档
gulp.task('api', (cb) => {
var output = jdtomk.renderSync({
files: './packages/**/*.{vue,js}',
configure: './jsdoc.conf.json',
'module-index-format': 'table'
});
fs.writeFileSync('./docs/api.md', output);
cb()
});
buildTasks.push('build-dev');
// 加入压缩作务
if (env === 'production') {
buildTasks = buildTasks.concat(['compress', 'cssmin'])
}
// 打包
gulp.task('build', series(...buildTasks))
gulp.task('watch', () => {
gulp.watch([
'src/**/*.{js,css,scss,sass,vue}',
'packages/**/*.{js,css,scss,sass,vue}',
'!packages/**/node_modules/**/*.{js,vue}'
], series('build'))
});
gulp.task('watch-api', () => {
gulp.watch(['packages/**/*.{vue,js}'], series('api'))
});
gulp.task('test', function (cb) {
exec('npm test', function (err) {
console.log('............')
if (err) return cb(err);
cb();
});
});
// execute gulp version --version 0.x.x
gulp.task('vs', (cb) => {
let version = process.argv.slice(2)[2];
let pkgs = glob.sync('./packages/**/package.json');
pkgs.unshift('./package.json');
console.log(pkgs)
pkgs.forEach(p => {
let pkgString = fs.readFileSync(p);
let pkg = JSON.parse(pkgString);
pkg.version = version;
fs.writeFileSync(p, JSON.stringify(pkg, null, 4), err => console.log(err));
})
cb()
})