-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (64 loc) · 1.75 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
const
gulp = require("gulp"),
exec = require('child_process').exec,
webpack = require("webpack-stream"),
ts = require('gulp-typescript'),
named = require("vinyl-named"),
browserSync = require("browser-sync").create(),
del = require("del"),
moduleName = "MVVM",
webpackConfig = require("./webpack.config")(moduleName),
output = "./dist",
declarationDir = "./types",
srcFolder = "./src";
function clean() {
return del(output);
}
function generateScript(webpackConfig) {
return gulp
.src(`${srcFolder}/index.ts`)
.pipe(named())
.pipe(webpack(webpackConfig))
.pipe(gulp.dest(output));
}
function script() {
const config = { ...{}, ...webpackConfig };
config.mode = "development";
return generateScript(config);
}
function _build() {
const config = { ...{}, ...webpackConfig };
config.mode = "production";
return generateScript(config);
}
function start() {
browserSync.init({
port: 8080,
server: {
baseDir: "./"
// files: [
// 'dist/*.css',
// 'dist/*.js',
// ]
}
});
gulp.watch(`${srcFolder}/**/*`, gulp.series(script, done => {
browserSync.reload();
done();
}));
}
const generateDtsTsConfig = ts.createProject('tsconfig.json', {
watch: false,
declaration: true,
});
function generateDts() {
del(declarationDir);
const result = gulp.src(`${srcFolder}/**/*.ts`)
.pipe(generateDtsTsConfig());
return result.dts
.pipe(gulp.dest(declarationDir));
}
exports.clean = clean;
exports.generateDts = generateDts;
exports.build = gulp.series(generateDts, clean, _build);
exports.start = gulp.series(clean, script, start);