-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
157 lines (127 loc) · 3.36 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
155
//
import chokidar from 'chokidar';
import gulp from 'gulp';
import path from 'path';
import del from 'promised-del';
import debounce from 'lodash.debounce';
import copy from './tasks/copy';
import babelify from './tasks/babelify';
import inject from './tasks/inject';
import scss from './tasks/scss';
import serverInitTask, {server as browser} from './tasks/server';
import systemjsBuilder from './tasks/systemjs-builder';
import hideStackFramesFrom from 'hide-stack-frames-from';
////
hideStackFramesFrom('babel-core', 'gulp', 'gulp-cli', 'gulp-babel');
const config = {
srcFolder: 'src',
outFolder: 'out',
srcFilesToCopy: [
'**/*.html',
'!sw/**/*',
'icons/**/*'
]
};
////
const babelTask = babelify({
cwd: config.srcFolder,
base: config.srcFolder,
src: [
'**/*.js',
'!sw/**/*'
],
dest: config.outFolder
});
function delOutputFolderTask() {
return del(['out']);
}
const serverTask = serverInitTask(config);
const copyNodeStuffTask = copy({
src: [
'node_modules/babel-core/browser-polyfill.min.js',
'jspm_packages/es6-module-loader.js',
'jspm_packages/system.src.js',
'jspm.config.js'
],
dest: config.outFolder
});
const copySrcStuffTask = copy({
cwd: config.srcFolder,
base: config.srcFolder,
src: config.srcFilesToCopy,
dest: config.outFolder
});
const injectTask = inject({
src: 'index.html',
cwd: config.outFolder,
dest: config.outFolder,
syncInjection: [
'critical.css',
'browser-polyfill.min.js',
'es6-module-loader.src.js',
'system.src.js',
'jspm.config.js'
],
asyncInjection: [
'critical.js'
]
});
const scssTask = scss({
src: '**/*.scss',
cwd: config.srcFolder,
dest: config.outFolder
});
const serviceWorkerBuildingTask = systemjsBuilder({
src: 'index',
cwd: config.srcFolder + '/sw',
dest: config.outFolder + '/sw.js',
isInSFXMode: true,
builderOptions: { sfxFormat: 'es6' }
});
////
gulp.task(delOutputFolderTask);
gulp.task(injectTask);
gulp.task(serverTask);
gulp.task(copyNodeStuffTask);
gulp.task(copySrcStuffTask);
gulp.task(serviceWorkerBuildingTask);
gulp.task('watch', function () {
const cwd = config.srcFolder;
const defaultChokidarOpts = { cwd, ignoreInitial: true}
const watch = ({callback, options = {}, src}) => {
return chokidar.watch(src, {...defaultChokidarOpts, ...options})
.on('all', debounce(callback, 500));
};
watch({
callback: ::gulp.series(babelTask, injectTask),
src: 'critical.js'
});
chokidar.watch([
'youtube-calendar-app.js',
'youtube-calendar-app/**/*.js'
], defaultChokidarOpts)
.on('all', ::gulp.parallel([babelTask]));
chokidar.watch('sw/**/*.js', defaultChokidarOpts)
.on('all', ::gulp.parallel([serviceWorkerBuildingTask]));
chokidar.watch(config.srcFilesToCopy, defaultChokidarOpts)
.on('all', ::gulp.series(copySrcStuffTask, injectTask));
// force reload
chokidar.watch('**/*.scss', defaultChokidarOpts)
.on('all', ::gulp.series(scssTask, ::browser.reload));
// reload on output change
chokidar.watch('**/*', { ...defaultChokidarOpts, cwd: config.outFolder })
.on('all', debounce(::gulp.parallel(::browser.reload), 500));
});
gulp.task('default', gulp.series(
delOutputFolderTask,
gulp.parallel(
babelTask,
copyNodeStuffTask,
copySrcStuffTask,
serverTask,
serviceWorkerBuildingTask,
scssTask
),
injectTask,
'watch'
));