-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
52 lines (51 loc) · 1.61 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
import gulp from "gulp";
const {src, dest, parallel, watch: w} = gulp;
/*
*const gt = require("gulp-terser");
*const terser = require("terser");
*/
//import gobf from "gulp-javascript-obfuscator";
import gt from "gulp-terser";
import {minify} from "terser";
import debug from "gulp-debug";
import stripDebug from "gulp-strip-debug";
import {deleteSync} from "del";
import path from "path";
//const path = ["**/*.js", "!dist/**/*", "!itdfw*.js", "!gulpfile.js", "!.pnp", "!ecosystem,config.js"];
const searchPath = ["src/**/*.js"];
function js() {
return (
src(searchPath, {base: "src"})
.pipe(debug({title: "Ofuscando" /*, logger: Log*/}))
//.pipe(gif(cond, gt({}, terser.minify)))
//.pipe(stripDebug())
.pipe(gt({}, minify))
//.pipe(gobf({compact: true /*, controlFlowFlattening: true*/}))
.pipe(dest("dist/"))
);
}
function obfuscate(path) {
return (
src(path, {base: "src"})
.pipe(debug({title: "Ofuscando" /*, logger: Log*/}))
//.pipe(gif(cond, gt({}, terser.minify)))
//.pipe(stripDebug())
.pipe(gt({}, minify))
//.pipe(gobf({compact: true /*, controlFlowFlattening: true*/}))
.pipe(dest("dist/"))
);
}
function watch() {
const watcher = w(searchPath);
watcher.on("change", obfuscate);
watcher.on("add", obfuscate);
watcher.on("unlink", filePath => {
const filePathFromSrc = path.relative(path.resolve("src"), filePath);
const destFilePath = path.resolve("dist", filePathFromSrc);
console.log("Eliminando", destFilePath);
deleteSync(destFilePath);
});
return watcher;
}
export {watch, js};
export default parallel(js, watch);