diff --git a/gulpfile.ts b/gulpfile.ts
index ae44f86..5f74ca4 100644
--- a/gulpfile.ts
+++ b/gulpfile.ts
@@ -8,6 +8,7 @@ const del = require("del");
const gulp = require("gulp");
const tslint = require("gulp-tslint");
const rename = require("gulp-rename");
+const uglify = require("gulp-uglify");
const transform = require("gulp-transform");
const TSConfig = require("./tsconfig.json");
@@ -36,42 +37,37 @@ export class Gulpfile {
@Task() buildHTML() {
const project = this.buildConfig(es5Project);
return project
- .pipe(transform(content => {
- let links = [];
- let scripts = [];
- content = content
- .toString()
- .replace(/require\(['"](link|script)!(.*?)['"]\);\n?/g, (m, type, module) => {
- switch (type) {
- case "link":
- links.push(module);
- break;
- case "script":
- scripts.push(module);
- break;
- }
- return "";
- });
- return Buffer.from(
- links.map(module => `\n`).join("") +
- scripts.map(module => `\n`).join("") +
- ``
- );
- }))
+ .pipe(transform(this.htmlWrapper))
.pipe(rename({ extname: ".html" }))
.pipe(gulp.dest(join(this.dest, "html")));
}
+ @Task() buildHTMLMin() {
+ const project = this.buildConfig(es5Project, false, true);
+ return project
+ .pipe(transform(this.htmlWrapper))
+ .pipe(rename({ extname: ".min.html" }))
+ .pipe(gulp.dest(join(this.dest, "html")));
+ }
+
@Task() buildES5() {
return this.buildConfig(es5Project, "cjs");
}
+ @Task() buildES5Min() {
+ return this.buildConfig(es5Project, "cjs", true);
+ }
+
@Task() buildES6() {
return this.buildConfig(es6Project, "es6");
}
@SequenceTask() build() {
- return [ "clean", "lint", "buildES5", "buildES6", "buildHTML" ];
+ return [
+ "clean", "lint",
+ "buildES5", "buildES6", "buildHTML",
+ "buildES5Min", "buildHTMLMin"
+ ];
}
@Task() default() {
@@ -79,8 +75,14 @@ export class Gulpfile {
console.log("default task");
}
- private buildConfig(projectConfig, dest?) {
- const project = gulp.src(this.include.concat(this.srcTS)).pipe(projectConfig());
+ private buildConfig(projectConfig, dest?, min?) {
+ let project = gulp.src(this.include.concat(this.srcTS)).pipe(projectConfig());
+ if (min) {
+ project = project.pipe(uglify());
+ if (dest) {
+ project = project.pipe(rename({extname: ".min.js"}));
+ }
+ }
if (dest) {
return project.pipe(gulp.dest(join(this.dest, dest)));
}
@@ -88,4 +90,29 @@ export class Gulpfile {
return project;
}
}
+
+ private htmlWrapper(content) {
+ let links = [];
+ let scripts = [];
+
+ content = content
+ .toString()
+ .replace(/require\(['"](link|script)!(.*?)['"]\);\n?/g, (m, type, module) => {
+ switch (type) {
+ case "link":
+ links.push(module);
+ break;
+ case "script":
+ scripts.push(module);
+ break;
+ }
+ return "";
+ });
+
+ return Buffer.from(
+ links.map(module => `\n`).join("") +
+ scripts.map(module => `\n`).join("") +
+ ``
+ );
+ }
}