-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
87 lines (79 loc) · 1.96 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
const gulp = require('gulp');
const inject = require('gulp-inject-string');
const minify = require('gulp-uglify');
const rename = require('gulp-rename');
const stripDebug = require('gulp-strip-debug');
const webserver = require('gulp-webserver');
var buildTargetUrlPath = process.env.BUILD_TARGET_URL_PATH || './';
gulp.task('miniJS', done => {
gulp.src('js/*.js')
// replace file paths for assets
.pipe(inject.replace(
'var BASE_FILE_PATH = \'./\';',
`var BASE_FILE_PATH = '${buildTargetUrlPath}'`
))
.pipe(minify())
.pipe(stripDebug())
.pipe(gulp.dest('dist/'))
done();
});
gulp.task('injectSWPath', done => {
gulp.src('./sw-template.js')
.pipe(inject.replace(
'BASE_FILE_PATH = \'./\'',
`BASE_FILE_PATH = '${buildTargetUrlPath}'`
))
.pipe(rename('./sw.js'))
.pipe(gulp.dest('./'))
done();
});
gulp.task('injectHTMLSrc', done => {
gulp.src('./index-template.html')
// replace all js file paths
.pipe(inject.replace(
'src="./',
`src="${buildTargetUrlPath}`
))
// replace file path for favicon
.pipe(inject.replace(
'href="./',
`href="${buildTargetUrlPath}`
))
// replace file path for service worker
.pipe(inject.replace(
'./sw.js',
`${buildTargetUrlPath}sw.js`
))
// replace default scope for service worker
.pipe(inject.replace(
'scope: \'/\'',
`scope: '${buildTargetUrlPath}'`
))
.pipe(rename('index.html'))
.pipe(gulp.dest('./'))
done();
});
gulp.task('serve', () => {
gulp.src('./')
.pipe(webserver({
livereload: true,
open: true
}))
});
gulp.task('watch', () => {
gulp.watch('js/**', gulp.series('miniJS')),
gulp.watch('./*.html', gulp.series('injectHTMLSrc')),
gulp.watch('./sw.js', gulp.series('injectSWPath'));
return
});
gulp.task('dev', gulp.parallel(
'serve',
'watch'
)
);
gulp.task('default', gulp.parallel(
'miniJS',
'injectHTMLSrc',
'injectSWPath'
)
);