-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
100 lines (90 loc) · 2.09 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
'use strict'
const path = require('path')
const gulp = require('gulp')
const gulpfiles = require('gulpfiles')
const rename = require('gulp-rename')
const wrap = require('gulp-wrap')
const replace = require('gulp-replace')
const streamToPromise = require('gulp-stream-to-promise')
const myPath = {
temp: './.tmp/',
src: './src/',
dest: './dist/',
}
const FILENAME = 'gearbox'
// const NS = 'gearbox'
const modules = {
action: './bower_components/action/src/action.js',
template: './bower_components/underscore-template/src/underscore-template.js',
}
const scripts = {
[FILENAME + '.js']: [
'./src/core.js',
'./src/str.js',
'./src/root.js',
'./src/ua.js',
'./src/url.js',
'./src/dom.js',
]
}
// combine external modules
Object.keys(modules).forEach(function (key) {
scripts[FILENAME + '.js'].push(path.join(myPath.temp, key + '.js'))
})
gulp.task('clean', gulpfiles.del({
glob: path.join(myPath.dest, '*.*'),
}))
gulp.task('clean-temp', gulpfiles.del({
glob: path.join(myPath.temp, '*.*'),
}))
gulp.task('prepare-module', function () {
let tasks = []
Object.keys(modules).forEach(function (key) {
const src = modules[key]
let stream = gulp.src(src)
.pipe(wrap('*/\n<%= contents %>\n/*'))
.pipe(wrap({src: path.join(myPath.src, '_wrapper/mod-' + key + '.js')}))
.pipe(rename(key + '.js'))
.pipe(gulp.dest(myPath.temp))
tasks.push(streamToPromise(stream))
})
return Promise.all(tasks)
})
gulp.task('js', gulpfiles.concat({
rules: scripts,
dest: myPath.dest,
config: {
pipes: [
{
plugin: 'wrap',
config: '*/\n<%= contents %>\n/*',
},
{
plugin: 'wrap',
config: {src: path.join(myPath.src, '_wrapper/dist-trad.js')},
},
{
plugin: 'replace',
config: [/\/\*\* DEBUG_INFO_START \*\*\//g, '/*'],
},
{
plugin: 'replace',
config: [/\/\*\* DEBUG_INFO_END \*\*\//g, '*/'],
},
{
plugin: 'uglify',
rename: FILENAME + '.min.js',
config: {
preserveComments: 'some',
},
}
]
},
}))
gulp.task('dist', gulp.series([
'clean',
'clean-temp',
'prepare-module',
'js',
]))
gulp.task('default', gulp.series('dist'))