-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.prod.js
110 lines (95 loc) · 3.3 KB
/
build.prod.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var gulp = require('gulp');
var gutil = require('gulp-util');
var colors = gutil.colors;
var nodePath = require('path');
var streamqueue = require('streamqueue');
var es = require('event-stream');
var del = require("del");
var vinylPaths = require('vinyl-paths');
var replace = require('gulp-replace');
var print = require('gulp-print');
var conf = require('./build-tools/variables.js');
var bundling = require('./build-tools/build-scripts/bundling.js');
var pathTools = require('./build-tools/build-scripts/path-tools.js');
var compilation = require('./build-tools/build-scripts/compilation.js');
var common = require('./build.common.js');
var build = {};
build.compile = function(context) {
var compileProdSaas = function() {
return compilation.compileSass(conf.APP_DIR);
};
var compileProdTemplates = function() {
return compilation.compileAngularTemplates(conf.NGC_TSCONFIG);
}
var compileProdTypescript = function() {
return compilation.compileTypescript(conf.PROD_TSCONFIG, conf.APP_PROD);
}
var rxjsToEs = function () {
return
}
return streamqueue({ objectMode: true },
common.rxjsToEs(context),
compileProdSaas,
compileProdTemplates,
compileProdTypescript
);
};
build.commonBundle = function (context) {
var packages = [
pathTools.resolvePackagePath("zone.js"),
pathTools.resolvePackagePath("reflect-metadata"),
pathTools.resolvePackagePath("es6-shim"),
pathTools.resolvePackagePath("tslib")
];
var bundle = bundling.concatBundle("common.min.js", packages,
{ destDir: context.destDir, uglify: true, cache: true });
return bundle.stream;
};
build.appBundle = function(context){
let mainEntry = nodePath.join(conf.APP_ROLLUP_ENTRY);
var bundle = bundling.rollupFromEntry("app.min.js", mainEntry, { format: "iife" },
{ destDir: context.destDir, uglify: true, cache: false });
return bundle.stream;
};
build.assets = function(context) {
return gulp.src( "./assets/**/*.*")
.pipe(gulp.dest(nodePath.join(context.destDir, "assets")));
}
build.bundle = function(context) {
return es.merge(
build.commonBundle(context),
build.appBundle(context),
build.assets(context)
);
}
build.processIndexHtml = function (context) {
return gulp.src(context.indexHtmlPath)
.pipe(replace('<!-- prod --', '<!-- prod -->'))
.pipe(replace('-- end-prod -->', '<!-- end-prod -->'))
.pipe(replace('<!-- dev -->', '<!-- dev --'))
.pipe(replace('<!-- end-dev -->', '-- end-dev -->'))
.pipe(gulp.dest(context.destDir))
.pipe(print(file => { gutil.log('Processed --> ' file) }));
}
build.build = function(context) {
return streamqueue({ objectMode: true },
() => build.clean(context),
() => build.compile(context),
() => build.bundle(context),
() => build.processIndexHtml(context)
);
}
build.clean = function (context) {
gutil.log("Cleaning...");
return gulp.src([
conf.APP_DIR "/**/*.js",
conf.APP_DIR '/**/*.js.map',
conf.APP_DIR '/**/*.metadata.json',
conf.DIST_DIR,
conf.AOT_DIR,
context.destDir
])
.pipe(vinylPaths(del))
.on('end', () => gutil.log("Cleaning done."));
};
module.exports = build;