Skip to content

Commit 921b3db

Browse files
committed
feat(build): add build:watch task to rebuild library on change on *.ts, *.html, *.scss files
Closes #98
1 parent 85c77f7 commit 921b3db

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ If you find next sections way too long, here is a quick summary for you:
5656
* **Library main tasks**:
5757
* Testing Library: `gulp test`
5858
* Building Library: `gulp build`
59+
* Watching source files and auto-rebuilding Library: `gulp build:watch`
60+
* Watching source files and auto-rebuilding Library (without running tests): `gulp build:watch-fast`
5961
* **Releasing Library**: `gulp release --version=[major|minor|patch]`
6062
* **Demo app main tasks**:
6163
* **Serving demo app**: `gulp serve:demo`
@@ -277,6 +279,8 @@ Here are the most important `gulp` tasks to use during your development workflow
277279
Task | Purpose
278280
:-----------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------
279281
`gulp build` | Builds and packages your library under the `dist/` folder.
282+
`gulp build:watch` | Watches the source files (*.ts, *.html and *.scss) and re-builds your library upon changes (useful for live refresh of demo app during development).
283+
`gulp build:watch-fast` | Watches the source files (*.ts, *.html and *.scss) and re-builds your library upon changes (without running tests).
280284
`gulp test` | Launches the tests (`*.spec.ts`) you wrote in `src/` and run code coverage on them. The coverage report can be found in `coverage/` folder
281285
`gulp test:watch` | Launches tests in watch mode. Every changes in `*.spec.ts`
282286
`gulp test:watch-no-cc` | Same as `gulp test:watch` but files do not get instrumented for code coverage (useful for debugging)

app/templates/_gulpfile.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,37 @@ gulp.task('ng-compile',() => {
261261
});
262262
});
263263

264-
// Lint, Prepare Build, <% if(!skipStyles) { %>, Sass to css, Inline templates & Styles<% } %> and Compile
264+
// Lint, Prepare Build, <% if(!skipStyles) { %>, Sass to css, Inline templates & Styles<% } %> and Ng-Compile
265265
gulp.task('compile', (cb) => {
266266
runSequence('lint', 'pre-compile', 'inline-templates', 'ng-compile', cb);
267267
});
268268

269-
// Watch changes on (*.ts, *.html<% if(!skipStyles) { %>, *.sass<% } %>) and Compile
270-
gulp.task('watch', () => {
271-
gulp.watch([config.allTs, config.allHtml, <% if(!skipStyles) { %>config.allSass<% } %>], ['compile']);
272-
});
273-
274269
// Build the 'dist' folder (without publishing it to NPM)
275270
gulp.task('build', ['clean'], (cb) => {
276271
runSequence('compile', 'test', 'npm-package', 'rollup-bundle', cb);
277272
});
278273

274+
// Same as 'build' but without cleaning temp folders (to avoid breaking demo app, if currently being served)
275+
gulp.task('build-watch', (cb) => {
276+
runSequence('compile', 'test', 'npm-package', 'rollup-bundle', cb);
277+
});
278+
279+
// Same as 'build-watch' but without running tests
280+
gulp.task('build-watch-no-tests', (cb) => {
281+
runSequence('compile', 'npm-package', 'rollup-bundle', cb);
282+
});
283+
284+
// Watch changes on (*.ts, *.html<% if(!skipStyles) { %>, *.sass<% } %>) and Re-build library
285+
gulp.task('build:watch', () => {
286+
gulp.watch([config.allTs, config.allHtml, <% if(!skipStyles) { %>config.allSass<% } %>], ['build-watch']);
287+
});
288+
289+
// Watch changes on (*.ts, *.html<% if(!skipStyles) { %>, *.sass<% } %>) and Re-build library (without running tests)
290+
gulp.task('build:watch-fast', () => {
291+
gulp.watch([config.allTs, config.allHtml, <% if(!skipStyles) { %>config.allSass<% } %>], ['build-watch-no-tests']);
292+
});
293+
294+
279295
/////////////////////////////////////////////////////////////////////////////
280296
// Packaging Tasks
281297
/////////////////////////////////////////////////////////////////////////////
@@ -448,26 +464,6 @@ gulp.task('test:demo', () => {
448464
return execDemoCmd('test --preserve-symlinks', { cwd: `${config.demoDir}`});
449465
});
450466

451-
gulp.task('test:demo-ssr', () => {
452-
// Load zone.js for the server.
453-
require('./demo/node_modules/zone.js/dist/zone-node');
454-
455-
// Import renderModuleFactory from @angular/platform-server.
456-
var renderModuleFactory = require('./demo/node_modules/@angular/platform-server').renderModuleFactory;
457-
458-
// Import the AOT compiled factory for your AppServerModule.
459-
// This import will change with the hash of your built server bundle.
460-
var AppServerModuleNgFactory = require('./demo/dist-server/main.bundle').AppServerModuleNgFactory;
461-
462-
// Load the index.html file.
463-
var index = require('fs').readFileSync('./demo/src/index.html', 'utf8');
464-
465-
// Render to HTML and log it to the console.
466-
return renderModuleFactory(AppServerModuleNgFactory, { document: index, url: '/' }).then(html => {
467-
console.log(html);
468-
});
469-
});
470-
471467
gulp.task('serve:demo', () => {
472468
return execDemoCmd('serve --preserve-symlinks<% if(useCompodoc){ %> --proxy-config proxy.conf.json<% } %>', { cwd: `${config.demoDir}` });
473469
});

0 commit comments

Comments
 (0)