1 | import * as plugins from './tsbundle.plugins';
|
2 | import * as paths from './tsbundle.paths';
|
3 |
|
4 | export class HtmlHandler {
|
5 | public sourceFilePath: string = plugins.path.join(paths.htmlDir, 'index.html');
|
6 | public targetFilePath: string = plugins.path.join(paths.distWebDir, 'index.html');
|
7 |
|
8 | public async checkIfExists() {
|
9 | return plugins.smartfile.fs.fileExists(this.sourceFilePath);
|
10 | }
|
11 |
|
12 |
|
13 | public async copyHtml(targetPathArg = this.targetFilePath) {
|
14 | if (!(await this.checkIfExists())) {
|
15 | return;
|
16 | }
|
17 | await plugins.smartfile.fs.copy(this.sourceFilePath, targetPathArg);
|
18 | }
|
19 |
|
20 |
|
21 | public async minifyHtml(targetPathArg = this.targetFilePath) {
|
22 | if (!(await this.checkIfExists())) {
|
23 | return;
|
24 | }
|
25 | const fileString = plugins.smartfile.fs.toStringSync(this.sourceFilePath);
|
26 | const minifiedHtml = plugins.htmlMinifier.minify(fileString, {
|
27 | minifyCSS: true,
|
28 | minifyJS: true,
|
29 | sortAttributes: true,
|
30 | sortClassName: true,
|
31 | removeAttributeQuotes: true,
|
32 | collapseWhitespace: true,
|
33 | collapseInlineTagWhitespace: true,
|
34 | removeComments: true
|
35 | });
|
36 | plugins.smartfile.memory.toFsSync(minifiedHtml, targetPathArg);
|
37 | }
|
38 | }
|