-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
86 lines (73 loc) · 2.1 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
const { series, parallel, watch, src, dest } = require('gulp');
const clean = require('gulp-clean');
const babel = require("gulp-babel");
var browserSync = require('browser-sync').create();
const serveFolder = './serve'
const SRC = './webapp'
const copysrc = [
`${SRC}/**/*`,
`!${SRC}/**/*.ts`,
`!${SRC}/**/*.tsx`,
`!${SRC}/**/*.js`,
`!${SRC}/resources/**/*`
];
const babelFiles = [
`${SRC}/**/*.js`,
`${SRC}/**/*.ts`,
`${SRC}/**/*.tsx`
];
const babelConfig = {
presets: [
'@babel/env',
["transform-ui5", {
"namespacePrefix": "sap.ui.demo.todo",
"noImportInteropPrefixes": ["sap/", "sap/ui/demo/todo"],
"onlyConvertNamedClass": true
}],
"@babel/preset-typescript"
],
plugins: ["module:ui5-jsx", "@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-optional-chaining"]
};
function cleanServe(cb) {
return src(serveFolder, {read: false, allowEmpty: true})
.pipe(clean({force: true}));
}
function copy() {
return src(copysrc)
.pipe(dest(serveFolder));
}
function transpileAll() {
return src(babelFiles)
.pipe(babel(babelConfig))
.pipe(dest(serveFolder))
}
function serve(cb) {
browserSync.init({
server: {
baseDir: serveFolder
}
});
}
function babelWatch() {
watch([`${SRC}/**/*.{js,ts,tsx}`], {interval: 300})
.on('change', function(path) {
console.log(`babel changed: ${path}`);
return src(path, {base: `${SRC}/`})
.pipe(babel(babelConfig))
.on('error', function (e)
{
console.error(e);
this.emit('end');
})
.pipe(dest(serveFolder));
}
);
}
function copyWatch() {
watch([`${SRC}/**/*`, `!${SRC}/**/*.{js,ts,tsx}`], {interval: 300})
.on('change', (path) => src(path, { base: `${SRC}/` })
.pipe(dest(`${serveFolder}/`))
);
}
exports.serve = series(cleanServe, parallel(copy, transpileAll), parallel(copyWatch, babelWatch, serve));
// livereload