forked from surfinzap/typopo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
109 lines (97 loc) · 2.21 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
const gulp = require('gulp');
const browsersync = require("browser-sync").create();
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const browserify = require('browserify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
var paths = {
dev: {
html: 'demo/typopo-demo.html',
index: 'typopo-demo.html',
name: 'typopo_browser.built.js',
dest: 'build/'
},
browser: {
src: 'src/browser_typopo.js',
name: 'typopo.min.js',
dest: 'dist/'
},
npm: {
src: 'src/typopo.js',
name: 'typopo_dist.min.js',
dest: 'dist/'
}
};
/*
* Define our tasks using plain functions
*/
function devBrowserBuild() {
return browserify({entries: paths.browser.src, debug: true})
.transform("babelify")
.bundle()
.pipe(source(paths.dev.name))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest(paths.dev.dest))
}
function browserBuild() {
return browserify({ entries: paths.browser.src, debug: false })
.transform(babelify)
.bundle()
.pipe(source(paths.browser.name))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(paths.browser.dest));
}
function npmBuild() {
return browserify({entries: paths.npm.src}, {standalone: 'typopo'})
.transform("babelify")
.bundle()
.pipe(source(paths.npm.name))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(paths.npm.dest))
}
function copyHtmlToDest() {
return gulp
.src(paths.dev.html)
.pipe(gulp.dest(paths.dev.dest));
}
function watchFiles() {
gulp.watch(
[
paths.npm.src,
paths.browser.src,
paths.dev.html,
"./src/**/*",
],
gulp.series(devBrowserBuild, copyHtmlToDest, browserSyncReload)
);
}
// BrowserSync
function browserSync(done) {
browsersync.init({
server: {
baseDir: 'build/',
index: 'typopo-demo.html'
},
port: 3000
});
done();
}
// BrowserSync Reload
function browserSyncReload(done) {
browsersync.reload();
done();
}
const watch = gulp.parallel(watchFiles, browserSync);
const build = gulp.parallel(npmBuild, browserBuild);
exports.watch = watch;
exports.build = build;
/*
* Define default task that can be called by just running `gulp` from cli
*/
exports.default = build;