Skip to content

Commit 508b141

Browse files
devversionmmalerba
authored andcommitted
build: minify html before inlining resources (#4877)
* build: minify html before inlining resources * Now minifies the HTML files before inlining the resources. This drops unnecessary whitespace due to previous line breaks and developers can easily test with Material components. Fixes #1596 * Address comment
1 parent 3f08e37 commit 508b141

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

tools/gulp/packaging/build-tasks-gulp.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import {task, watch} from 'gulp';
1+
import {task, watch, src, dest} from 'gulp';
22
import {join} from 'path';
33
import {main as tsc} from '@angular/tsc-wrapped';
4-
import {SOURCE_ROOT, DIST_ROOT} from '../build-config';
4+
import {SOURCE_ROOT, DIST_ROOT, HTML_MINIFIER_OPTIONS} from '../build-config';
55
import {sequenceTask, sassBuildTask, copyTask, triggerLivereload} from '../util/task_helpers';
66
import {composeRelease} from './build-release';
77
import {buildPackageBundles} from './build-bundles';
88

99
// There are no type definitions available for these imports.
1010
const inlineResources = require('../../../scripts/release/inline-resources');
11+
const htmlmin = require('gulp-htmlmin');
1112

1213
/**
1314
* Creates a set of gulp tasks that can build the specified package.
@@ -25,8 +26,11 @@ export function createPackageBuildTasks(packageName: string, requiredPackages: s
2526
// Paths to the different output files and directories.
2627
const esmMainFile = join(packageOut, 'index.js');
2728

28-
// Glob that matches all assets that should be copied to the package.
29-
const assetsGlob = join(packageRoot, '**/*.+(html|scss|css)');
29+
// Glob that matches all style files that need to be copied to the package output.
30+
const stylesGlob = join(packageRoot, '**/*.+(scss|css)');
31+
32+
// Glob that matches every HTML file in the current package.
33+
const htmlGlob = join(packageRoot, '**/*.html');
3034

3135
/**
3236
* Main tasks for the package building. Tasks execute the different sub-tasks in the correct
@@ -70,10 +74,16 @@ export function createPackageBuildTasks(packageName: string, requiredPackages: s
7074
/**
7175
* Asset tasks. Building SASS files and inlining CSS, HTML files into the ESM output.
7276
*/
73-
task(`${packageName}:assets`, [`${packageName}:assets:scss`, `${packageName}:assets:html`]);
77+
task(`${packageName}:assets`, [
78+
`${packageName}:assets:scss`, `${packageName}:assets:copy-styles`, `${packageName}:assets:html`
79+
]);
7480

7581
task(`${packageName}:assets:scss`, sassBuildTask(packageOut, packageRoot, true));
76-
task(`${packageName}:assets:html`, copyTask(assetsGlob, packageOut));
82+
task(`${packageName}:assets:copy-styles`, copyTask(stylesGlob, packageOut));
83+
task(`${packageName}:assets:html`, () => {
84+
return src(htmlGlob).pipe(htmlmin(HTML_MINIFIER_OPTIONS)).pipe(dest(packageOut));
85+
});
86+
7787
task(`${packageName}:assets:inline`, () => inlineResources(packageOut));
7888

7989
/**

0 commit comments

Comments
 (0)