-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
68 lines (55 loc) · 1.72 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
'use strict';
// Dependencies
var gulp = require('gulp');
var browserify = require("browserify");
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var tsify = require("tsify");
var eventStream = require('event-stream');
var rename = require('gulp-rename');
// Shared variables
var sourceFiles = {};
sourceFiles.root = 'src/';
sourceFiles.htmlFilesRoot = sourceFiles.root;
sourceFiles.allhtmlFilesSelector = sourceFiles.htmlFilesRoot + '*.html';
var targetFiles = {};
targetFiles.root = 'target/';
targetFiles.staticRoot = targetFiles.root + 'static/';
targetFiles.jsRoot = targetFiles.staticRoot + 'scripts/';
targetFiles.htmlFilesRoot = targetFiles.root + '';
// Task definitions
gulp.task('default', ['scripts', 'htmlFiles']);
var scriptEntrypoints = ['index.tsx'];
var browserifiedConfig = {
basedir: './src/scripts/',
debug: true,
cache: {},
packageCache: {}
};
gulp.task('scripts', () => { unwatchifiedScripts() });
function unwatchifiedScripts(entryPoints) {
entryPoints = entryPoints || scriptEntrypoints;
var streams = entryPoints.map((entrypointName) => {
var currentBrowserifyConfig = Object.assign({}, browserifiedConfig);
currentBrowserifyConfig.entries = entrypointName;
var browserified = browserify(currentBrowserifyConfig)
.plugin(tsify);
return doScripts(
browserified,
entrypointName);
});
return eventStream.merge(streams);
}
function doScripts(specificBrowserify, entrypointName) {
return specificBrowserify
.bundle()
.pipe(source(entrypointName))
.pipe(rename({
extname: '.js'
}))
.pipe(gulp.dest(targetFiles.jsRoot));
}
gulp.task('htmlFiles', function () {
gulp.src(sourceFiles.allhtmlFilesSelector)
.pipe(gulp.dest(targetFiles.htmlFilesRoot));
});