Skip to content

build: minify html before inlining resources #4877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions tools/gulp/packaging/build-tasks-gulp.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {task, watch} from 'gulp';
import {task, watch, src, dest} from 'gulp';
import {join} from 'path';
import {main as tsc} from '@angular/tsc-wrapped';
import {SOURCE_ROOT, DIST_ROOT} from '../build-config';
import {SOURCE_ROOT, DIST_ROOT, HTML_MINIFIER_OPTIONS} from '../build-config';
import {sequenceTask, sassBuildTask, copyTask, triggerLivereload} from '../util/task_helpers';
import {composeRelease} from './build-release';
import {buildPackageBundles} from './build-bundles';

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

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

// Glob that matches all assets that should be copied to the package.
const assetsGlob = join(packageRoot, '**/*.+(html|scss|css)');
// Glob that matches all style files that need to be copied to the package output.
const stylesGlob = join(packageRoot, '**/*.+(scss|css)');

// Glob that matches every HTML file in the current package.
const htmlGlob = join(packageRoot, '**/*.html');

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

task(`${packageName}:assets:scss`, sassBuildTask(packageOut, packageRoot, true));
task(`${packageName}:assets:html`, copyTask(assetsGlob, packageOut));
task(`${packageName}:assets:copy-styles`, copyTask(stylesGlob, packageOut));
task(`${packageName}:assets:html`, () => {
return src(htmlGlob).pipe(htmlmin(HTML_MINIFIER_OPTIONS)).pipe(dest(packageOut));
});

task(`${packageName}:assets:inline`, () => inlineResources(packageOut));

/**
Expand Down