Skip to content

Commit e4ac04d

Browse files
devversionjelbourn
authored andcommitted
build: speed-up stylesheet building (#12426)
* Switches back from `dart-sass` to `node-sass` due to a pretty huge slow-down we noticed (can be revisited) * No longer copies all SCSS files to the temporary `package` output just in favor of the demo-app (slows down unnecessarily). This now allows us to live-reload theme changes within a second. * No longer rebuilds all package SCSS files twice for the ES5 output (rel: #7403)
1 parent 08e6653 commit e4ac04d

File tree

9 files changed

+103
-161
lines changed

9 files changed

+103
-161
lines changed

package-lock.json

Lines changed: 20 additions & 98 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@
8484
"gulp-cli": "^1.3.0",
8585
"gulp-connect": "^5.0.0",
8686
"gulp-conventional-changelog": "^1.1.3",
87-
"gulp-dart-sass": "^0.9.0",
8887
"gulp-dom": "^0.9.17",
8988
"gulp-flatten": "^0.3.1",
9089
"gulp-highlight-files": "^0.0.5",
9190
"gulp-htmlmin": "^3.0.0",
9291
"gulp-if": "^2.0.2",
9392
"gulp-markdown": "^1.2.0",
9493
"gulp-rename": "^1.2.2",
94+
"gulp-sass": "^3.1.0",
9595
"gulp-transform": "^2.0.0",
9696
"gulp-util": "^3.0.8",
9797
"hammerjs": "^2.0.8",
@@ -111,6 +111,7 @@
111111
"minimatch": "^3.0.4",
112112
"minimist": "^1.2.0",
113113
"moment": "^2.18.1",
114+
"node-sass": "^4.5.3",
114115
"parse5": "^5.0.0",
115116
"protractor": "^5.2.0",
116117
"request": "^2.83.0",
@@ -119,7 +120,6 @@
119120
"rollup-plugin-alias": "^1.4.0",
120121
"rollup-plugin-node-resolve": "^3.0.3",
121122
"run-sequence": "^1.2.2",
122-
"sass": "^1.10.1",
123123
"scss-bundle": "^2.0.1-beta.7",
124124
"selenium-webdriver": "^3.6.0",
125125
"sorcery": "^0.10.0",

src/demo-app/theme.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@import '../../dist/packages/material/core/theming/all-theme';
1+
@import '../lib/core/theming/all-theme';
2+
23
// Plus imports for other components in your app.
34

45
// Include the common styles for Angular Material. We include this here so that you only

tools/gulp/tasks/development.ts

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {task} from 'gulp';
1+
import {task, dest} from 'gulp';
22
import {tsBuildTask, copyTask, serverTask} from '../util/task_helpers';
33
import {join} from 'path';
44
import {
5-
buildConfig, copyFiles, buildScssTask, sequenceTask, watchFiles
5+
buildConfig, copyFiles, buildScssPipeline, sequenceTask, watchFiles
66
} from 'material2-build-tools';
77
import {
88
cdkPackage,
@@ -43,53 +43,35 @@ const vendorGlob = `+(${appVendors.join('|')})/**/*.+(html|css|js|map)`;
4343
/** Glob that matches all assets that need to be copied to the output. */
4444
const assetsGlob = join(appDir, `**/*.+(html|css|svg|ico)`);
4545

46-
task(':watch:devapp', () => {
47-
watchFiles(join(appDir, '**/*.ts'), [':build:devapp:ts']);
48-
watchFiles(join(appDir, '**/*.scss'), [':build:devapp:scss']);
49-
watchFiles(join(appDir, '**/*.html'), [':build:devapp:assets']);
50-
51-
// Custom watchers for all packages that are used inside of the demo-app. This is necessary
52-
// because we only want to build the changed package (using the build-no-bundles task).
53-
watchFiles(join(cdkPackage.sourceDir, '**/*'), ['cdk:build-no-bundles']);
54-
watchFiles(join(materialPackage.sourceDir, '**/!(*.scss)'), ['material:build-no-bundles']);
55-
watchFiles(join(materialPackage.sourceDir, '**/*.scss'), [':build:devapp:material-with-styles']);
56-
watchFiles(join(momentAdapterPackage.sourceDir, '**/*'),
57-
['material-moment-adapter:build-no-bundles']);
58-
watchFiles(join(materialExperimentalPackage.sourceDir, '**/*'),
59-
['material-experimental:build-no-bundles']);
60-
watchFiles(join(cdkExperimentalPackage.sourceDir, '**/*'),
61-
['cdk-experimental:build-no-bundles']);
62-
watchFiles(join(examplesPackage.sourceDir, '**/*'), ['material-examples:build-no-bundles']);
63-
});
64-
6546
/** Path to the demo-app tsconfig file. */
6647
const tsconfigPath = join(appDir, 'tsconfig-build.json');
6748

6849
task(':build:devapp:ts', tsBuildTask(tsconfigPath));
69-
task(':build:devapp:scss', buildScssTask(outDir, appDir));
7050
task(':build:devapp:assets', copyTask(assetsGlob, outDir));
51+
task(':build:devapp:scss', () => buildScssPipeline(appDir).pipe(dest(outDir)));
7152

7253
task(':serve:devapp', serverTask(outDir, true));
7354

74-
// The themes for the demo-app are built by using the SCSS mixins from Material.
75-
// Therefore when SCSS files have been changed, the custom theme needs to be rebuilt.
76-
task(':build:devapp:material-with-styles', sequenceTask(
77-
'material:build-no-bundles', ':build:devapp:scss'
78-
));
79-
8055
task('build:devapp', sequenceTask(
8156
'cdk:build-no-bundles',
8257
'material:build-no-bundles',
8358
'cdk-experimental:build-no-bundles',
8459
'material-experimental:build-no-bundles',
8560
'material-moment-adapter:build-no-bundles',
86-
'build-examples-module', // The examples module needs to be built before building examples package
61+
'build-examples-module',
62+
// The examples module needs to be manually built before building examples package because
63+
// when using the `no-bundles` task, the package-specific pre-build tasks won't be executed.
8764
'material-examples:build-no-bundles',
8865
[':build:devapp:assets', ':build:devapp:scss', ':build:devapp:ts']
8966
));
9067

9168
task('serve:devapp', ['build:devapp'], sequenceTask([':serve:devapp', ':watch:devapp']));
9269

70+
/*
71+
* Development App deployment tasks. These can be used to run the dev-app outside of our
72+
* serve task with a middleware. e.g. on Firebase hosting.
73+
*/
74+
9375
/** Task that copies all vendors into the demo-app package. Allows hosting the app on firebase. */
9476
task('stage-deploy:devapp', ['build:devapp'], () => {
9577
copyFiles(join(projectDir, 'node_modules'), vendorGlob, join(outDir, 'node_modules'));
@@ -118,3 +100,40 @@ task('deploy:devapp', ['stage-deploy:devapp'], () => {
118100
.then(() => { console.log('Successfully deployed the demo-app to firebase'); process.exit(0); })
119101
.catch((err: any) => { console.log(err); process.exit(1); });
120102
});
103+
104+
/*
105+
* Development app watch task. This task ensures that only the packages that have been affected
106+
* by a file-change are being rebuilt. This speeds-up development and makes working on Material
107+
* easier.
108+
*/
109+
110+
task(':watch:devapp', () => {
111+
watchFiles(join(appDir, '**/*.ts'), [':build:devapp:ts']);
112+
watchFiles(join(appDir, '**/*.scss'), [':build:devapp:scss']);
113+
watchFiles(join(appDir, '**/*.html'), [':build:devapp:assets']);
114+
115+
// Custom watchers for all packages that are used inside of the demo-app. This is necessary
116+
// because we only want to build the changed package (using the build-no-bundles task).
117+
118+
// CDK package watchers.
119+
watchFiles(join(cdkPackage.sourceDir, '**/*'), ['cdk:build-no-bundles']);
120+
121+
// Material package watchers.
122+
watchFiles(join(materialPackage.sourceDir, '**/!(*-theme).scss'), ['material:build-no-bundles']);
123+
watchFiles(join(materialPackage.sourceDir, '**/*-theme.scss'), [':build:devapp:scss']);
124+
125+
// Moment adapter package watchers
126+
watchFiles(join(momentAdapterPackage.sourceDir, '**/*'),
127+
['material-moment-adapter:build-no-bundles']);
128+
129+
// Material experimental package watchers
130+
watchFiles(join(materialExperimentalPackage.sourceDir, '**/*'),
131+
['material-experimental:build-no-bundles']);
132+
133+
// CDK experimental package watchers
134+
watchFiles(join(cdkExperimentalPackage.sourceDir, '**/*'),
135+
['cdk-experimental:build-no-bundles']);
136+
137+
// Example package watchers.
138+
watchFiles(join(examplesPackage.sourceDir, '**/*'), ['material-examples:build-no-bundles']);
139+
});

0 commit comments

Comments
 (0)