This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
gulpfile.js
172 lines (159 loc) ยท 4.29 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
// modules ๐ฅ
const gulp = require('gulp')
const head = require('gulp-header')
const uglify = require('gulp-uglify')
const rename = require('gulp-rename')
const qunit = require('node-qunit-phantomjs')
const rollup = require('rollup')
const babel = require('rollup-plugin-babel')
const cleanup = require('rollup-plugin-cleanup')
const resolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const pkg = require('./package.json')
// banner ๐ฉ
// added to all minified files
const banner = `/*
* <%= pkg.name %> - <%= pkg.description %>
* @version v<%= pkg.version %>
* @link <%= pkg.homepage %>
* @author <%= pkg.author %>
* @license <%= pkg.license %>
*/
`
// plugins ๐
// --------
// currently there are 4 ways to use reframe
// - reframe (vanilla js)
// - noframe (vanilla js)
// - jquery.reframe (jQuery/Zepto support for reframe)
// - jquery.noframe (jQuery/Zepto support for noframe)
const plugins = ['reframe', 'noframe', 'jquery.reframe', 'jquery.noframe']
// rollup plugin defaults
const resolveObj = {
jsnext: true,
main: true,
browser: true,
}
const excludeOjb = {
exclude: 'node_modules/**',
}
const rollupPlugins = [
resolve(resolveObj),
commonjs(),
babel(excludeOjb),
cleanup(),
]
// builds reframe
gulp.task('build:reframe', () => {
return rollup.rollup({
input: 'src/reframe.js',
plugins: rollupPlugins,
}).then((bundle) => {
bundle.write({
file: 'dist/reframe.js',
format: 'umd',
name: 'reframe',
sourcemap: false,
treeshake: false,
})
})
})
// builds reframe
gulp.task('build:reframe:es', () => {
return rollup.rollup({
input: 'src/reframe.js',
plugins: rollupPlugins,
}).then((bundle) => {
bundle.write({
file: 'dist/reframe.es.js',
format: 'es',
name: 'reframe',
sourcemap: false,
treeshake: false,
})
})
})
// builds noframe
gulp.task('build:noframe', () => {
return rollup.rollup({
input: 'src/noframe.js',
plugins: rollupPlugins,
}).then((bundle) => {
bundle.write({
file: 'dist/noframe.js',
format: 'umd',
name: 'noframe',
sourcemap: false,
treeshake: false,
})
})
})
// builds noframe
gulp.task('build:noframe:es', () => {
return rollup.rollup({
input: 'src/noframe.js',
plugins: rollupPlugins,
}).then((bundle) => {
bundle.write({
file: 'dist/noframe.es.js',
format: 'es',
name: 'noframe',
sourcemap: false,
treeshake: false,
})
})
})
// builds jquery reframe
gulp.task('build:jquery-reframe', () => {
return rollup.rollup({
input: 'src/jquery.reframe.js',
plugins: rollupPlugins,
}).then((bundle) => {
bundle.write({
file: 'dist/jquery.reframe.js',
format: 'umd',
name: 'reframe',
sourcemap: false,
treeshake: false,
})
})
})
// builds jquery noframe
gulp.task('build:jquery-noframe', () => {
return rollup.rollup({
input: 'src/jquery.noframe.js',
plugins: rollupPlugins,
}).then((bundle) => {
bundle.write({
file: 'dist/jquery.noframe.js',
format: 'umd',
name: 'noframe',
sourcemap: false,
treeshake: false,
})
})
})
// builds all reframe plugins
gulp.task('build', gulp.parallel('build:reframe', 'build:reframe:es', 'build:noframe', 'build:noframe:es', 'build:jquery-reframe', 'build:jquery-noframe'))
// minify
// minify all plugins ๐
gulp.task('minify', () => {
for (let i = 0; i < plugins.length; i += 1) {
const plugin = plugins[i]
return gulp.src(`dist/${plugin}.js`)
.pipe(uglify())
.pipe(head(banner, { pkg }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/'))
}
})
// tests โ๏ธ
// test each plugin
// user qunit with phantom
gulp.task('test:reframe', async () => qunit('tests/reframe/index.html'))
gulp.task('test:noframe', async () => qunit('tests/noframe/index.html'))
gulp.task('test:jquery-reframe', async () => qunit('tests/jquery-reframe/index.html'))
gulp.task('test:jquery-noframe', async () => qunit('tests/jquery-noframe/index.html'))
gulp.task('test', gulp.parallel('test:reframe', 'test:noframe', 'test:jquery-reframe', 'test:jquery-noframe'))
gulp.task('default', gulp.parallel('build', 'minify', 'test'))