Skip to content

Commit 5227bc3

Browse files
committed
chore(dev-app): prevent multiple reloads per file change
Prevents the local dev app from reloading 5-6 times whenever a file changes. Adds a filter that only watches for the bundle (which also contains all of the CSS and HTML), theme changes and changes to the demo apps. Fixes #1681.
1 parent a0d85d8 commit 5227bc3

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

tools/gulp/task_helpers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,15 @@ export function vendorTask() {
185185
}));
186186
}
187187

188+
export type livereloadOptions = boolean | {
189+
enable: boolean;
190+
filter: (filename: string, callback: (isAllowed: boolean) => void) => void;
191+
}
188192

189193
/** Create a task that serves the dist folder. */
190-
export function serverTask(liveReload = true,
194+
export function serverTask(liveReload: livereloadOptions = true,
191195
streamCallback: (stream: NodeJS.ReadWriteStream) => void = null) {
196+
192197
return () => {
193198
const stream = gulp.src('dist').pipe(gulpServer({
194199
livereload: liveReload,

tools/gulp/tasks/development.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {
1010

1111
const appDir = path.join(SOURCE_ROOT, 'demo-app');
1212
const outDir = DIST_ROOT;
13-
13+
const LIVERELOAD_PATTERNS = [
14+
/material\.umd\.js$/,
15+
/-demo\.[a-z]+$/,
16+
/\/theming\/prebuilt/
17+
];
1418

1519
task(':watch:devapp', () => {
1620
watch(path.join(appDir, '**/*.ts'), [':build:devapp:ts']);
@@ -25,7 +29,13 @@ task(':build:devapp:scss', [':build:components:scss'], sassBuildTask(outDir, app
2529
task(':build:devapp:assets', copyTask(appDir, outDir));
2630
task('build:devapp', buildAppTask('devapp'));
2731

28-
task(':serve:devapp', serverTask());
32+
task(':serve:devapp', serverTask({
33+
enable: true,
34+
filter: (filename: string, callback: Function) => {
35+
callback(LIVERELOAD_PATTERNS.some(pattern => pattern.test(filename)));
36+
}
37+
}));
38+
2939
task('serve:devapp', ['build:devapp'], sequenceTask(
3040
[':serve:devapp', ':watch:components', ':watch:devapp']
3141
));

0 commit comments

Comments
 (0)