UNPKG

1.74 kBJavaScriptView Raw
1const gulp = require('gulp');
2const sass = require('node-sass');
3const inlineTemplates = require('gulp-inline-ng2-template');
4const exec = require('child_process').exec;
5
6/**
7 * Inline templates configuration.
8 * @see https://github.com/ludohenin/gulp-inline-ng2-template
9 */
10const INLINE_TEMPLATES = {
11 SRC: './src/**/*.ts',
12 DIST: './tmp/src-inlined',
13 CONFIG: {
14 base: '/src',
15 target: 'es6',
16 useRelativePaths: true,
17 styleProcessor: compileSass
18 }
19};
20
21/**
22 * Inline external HTML and SCSS templates into Angular component files.
23 * @see: https://github.com/ludohenin/gulp-inline-ng2-template
24 */
25gulp.task('inline-templates', () => {
26 return gulp.src(INLINE_TEMPLATES.SRC)
27 .pipe(inlineTemplates(INLINE_TEMPLATES.CONFIG))
28 .pipe(gulp.dest(INLINE_TEMPLATES.DIST));
29});
30
31/**
32 * Build ESM by running npm task.
33 * This is a temporary solution until ngc is supported --watch mode.
34 * @see: https://github.com/angular/angular/issues/12867
35 */
36gulp.task('build:esm', ['inline-templates'], (callback) => {
37 exec('npm run ngcompile', function (error, stdout, stderr) {
38 console.log(stdout, stderr);
39 callback(error)
40 });
41});
42
43/**
44 * Implements ESM build watch mode.
45 * This is a temporary solution until ngc is supported --watch mode.
46 * @see: https://github.com/angular/angular/issues/12867
47 */
48gulp.task('build:esm:watch', ['build:esm'], () => {
49 gulp.watch('src/**/*', ['build:esm']);
50});
51
52/**
53 * Compile SASS to CSS.
54 * @see https://github.com/ludohenin/gulp-inline-ng2-template
55 * @see https://github.com/sass/node-sass
56 */
57function compileSass(path, ext, file, callback) {
58 let compiledCss = sass.renderSync({
59 file: path,
60 outputStyle: 'compressed',
61 });
62 callback(null, compiledCss.css);
63}