tsbundle/ts/tsbundle.htmlhandler.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-06-16 15:47:34 +00:00
import * as plugins from './tsbundle.plugins';
import * as paths from './tsbundle.paths';
export class HtmlHandler {
public sourceFilePath: string = plugins.path.join(paths.htmlDir, 'index.html');
public targetFilePath: string = plugins.path.join(paths.distWebDir, 'index.html');
2019-07-17 09:54:49 +00:00
public async checkIfExists () {
return plugins.smartfile.fs.fileExists(this.sourceFilePath);
}
2019-06-16 15:47:34 +00:00
// copies the html
public async copyHtml() {
2019-07-17 09:54:49 +00:00
if (!(await this.checkIfExists)) {
return;
}
2019-06-16 15:47:34 +00:00
await plugins.smartfile.fs.copy(
this.sourceFilePath,
this.targetFilePath
);
}
// copies and minifies the html
public async minifyHtml() {
2019-07-17 09:54:49 +00:00
if (!(await this.checkIfExists)) {
return;
}
2019-06-16 15:47:34 +00:00
const fileString = plugins.smartfile.fs.toStringSync(this.sourceFilePath);
const minifiedHtml = plugins.htmlMinifier.minify(fileString, {
minifyCSS: true,
minifyJS: true,
sortAttributes: true,
sortClassName: true,
2019-06-16 15:52:20 +00:00
removeAttributeQuotes: true,
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeComments: true
2019-06-16 15:47:34 +00:00
});
plugins.smartfile.memory.toFsSync(minifiedHtml, this.targetFilePath);
}
}