1
- import { task , watch } from 'gulp' ;
1
+ import { task , watch , src , dest } from 'gulp' ;
2
2
import * as path from 'path' ;
3
3
4
- import { DIST_COMPONENTS_ROOT , PROJECT_ROOT , COMPONENTS_DIR } from '../constants' ;
4
+ import {
5
+ DIST_COMPONENTS_ROOT , PROJECT_ROOT , COMPONENTS_DIR , HTML_MINIFIER_OPTIONS
6
+ } from '../constants' ;
5
7
import { sassBuildTask , tsBuildTask , execNodeTask , copyTask , sequenceTask } from '../task_helpers' ;
6
8
import { writeFileSync } from 'fs' ;
7
9
8
10
// No typings for these.
9
11
const inlineResources = require ( '../../../scripts/release/inline-resources' ) ;
10
12
const rollup = require ( 'rollup' ) . rollup ;
13
+ const gulpMinifyCss = require ( 'gulp-clean-css' ) ;
14
+ const gulpMinifyHtml = require ( 'gulp-htmlmin' ) ;
15
+ const gulpIf = require ( 'gulp-if' ) ;
11
16
12
17
13
18
// NOTE: there are two build "modes" in this file, based on which tsconfig is used.
@@ -23,9 +28,9 @@ const tsconfigPath = path.relative(PROJECT_ROOT, path.join(COMPONENTS_DIR, 'tsco
23
28
24
29
/** [Watch task] Rebuilds (ESM output) whenever ts, scss, or html sources change. */
25
30
task ( ':watch:components' , ( ) => {
26
- watch ( path . join ( COMPONENTS_DIR , '**/*.ts' ) , [ ': build:components:rollup ' ] ) ;
27
- watch ( path . join ( COMPONENTS_DIR , '**/*.scss' ) , [ ': build:components:rollup ' ] ) ;
28
- watch ( path . join ( COMPONENTS_DIR , '**/*.html' ) , [ ': build:components:rollup ' ] ) ;
31
+ watch ( path . join ( COMPONENTS_DIR , '**/*.ts' ) , [ 'build:components' ] ) ;
32
+ watch ( path . join ( COMPONENTS_DIR , '**/*.scss' ) , [ 'build:components' ] ) ;
33
+ watch ( path . join ( COMPONENTS_DIR , '**/*.html' ) , [ 'build:components' ] ) ;
29
34
} ) ;
30
35
31
36
@@ -41,11 +46,18 @@ task(':build:components:assets', copyTask([
41
46
path . join ( PROJECT_ROOT , 'README.md' ) ,
42
47
] , DIST_COMPONENTS_ROOT ) ) ;
43
48
49
+ /** Minifies the HTML and CSS assets in the distribution folder. */
50
+ task ( ':build:components:assets:minify' , ( ) => {
51
+ return src ( '**/*.+(html|css)' , { cwd : DIST_COMPONENTS_ROOT } )
52
+ . pipe ( gulpIf ( / .c s s $ / , gulpMinifyCss ( ) , gulpMinifyHtml ( HTML_MINIFIER_OPTIONS ) ) )
53
+ . pipe ( dest ( DIST_COMPONENTS_ROOT ) ) ;
54
+ } ) ;
55
+
44
56
/** Builds scss into css. */
45
57
task ( ':build:components:scss' , sassBuildTask ( DIST_COMPONENTS_ROOT , COMPONENTS_DIR ) ) ;
46
58
47
59
/** Builds the UMD bundle for all of Angular Material. */
48
- task ( ':build:components:rollup' , [ ':build:components:inline' ] , ( ) => {
60
+ task ( ':build:components:rollup' , ( ) => {
49
61
const globals : { [ name : string ] : string } = {
50
62
// Angular dependencies
51
63
'@angular/core' : 'ng.core' ,
@@ -102,13 +114,23 @@ task(':build:components:inline', sequenceTask(
102
114
':inline-resources' ,
103
115
) ) ;
104
116
117
+ /** Builds components with minified HTML and CSS inlined into the built JS. */
118
+ task ( ':build:components:inline:release' , sequenceTask (
119
+ [ ':build:components:ts' , ':build:components:scss' , ':build:components:assets' ] ,
120
+ ':build:components:assets:minify' ,
121
+ ':inline-resources'
122
+ ) ) ;
123
+
105
124
/** Inlines resources (html, css) into the JS output (for either ESM or CJS output). */
106
125
task ( ':inline-resources' , ( ) => inlineResources ( DIST_COMPONENTS_ROOT ) ) ;
107
126
108
127
/** Builds components to ESM output and UMD bundle. */
109
- task ( 'build:components' , [ ':build:components:rollup' ] ) ;
128
+ task ( 'build:components' , sequenceTask ( ':build:components:inline' , ':build:components:rollup' ) ) ;
129
+ task ( 'build:components:release' , sequenceTask (
130
+ ':build:components:inline:release' , ':build:components:rollup'
131
+ ) ) ;
110
132
111
133
/** Generates metadata.json files for all of the components. */
112
- task ( ':build:components:ngc' , [ 'build:components' ] , execNodeTask (
134
+ task ( ':build:components:ngc' , [ 'build:components:release ' ] , execNodeTask (
113
135
'@angular/compiler-cli' , 'ngc' , [ '-p' , tsconfigPath ]
114
136
) ) ;
0 commit comments