Angular SystemJS Builder:在构建过程中缩小html和css

Angular SystemJS Builder:在构建过程中缩小html和css,angular,typescript,deployment,gulp,systemjs,Angular,Typescript,Deployment,Gulp,Systemjs,我正在学习如何使用systemjsbuilder 0.15.30捆绑使用typescript 2编写的Angular 2 rc.6应用程序。我使用gulp 3.9.1建造: 我的应用程序中的每个组件都有5个文件: 组件技术 component.html component.scss component.css(由下面的gulp任务1生成) component.min.html(由下面的gulp任务2生成) .ts导入要内联使用的.min.html和.css。我的目标是在一个步骤中缩小并捆绑这

我正在学习如何使用
systemjsbuilder 0.15.30
捆绑使用
typescript 2编写的
Angular 2 rc.6
应用程序。我使用
gulp 3.9.1
建造:

我的应用程序中的每个组件都有5个文件:

  • 组件技术
  • component.html
  • component.scss
  • component.css(由下面的gulp任务1生成)
  • component.min.html(由下面的gulp任务2生成)
.ts
导入要内联使用的
.min.html
.css
。我的目标是在一个步骤中缩小并捆绑这些内容,而不是首先生成它们

我目前有3个吞咽任务,我想合并成一个:

1.扫描所有文件夹;将
.scss
转换为同一目录中的小型
.css

gulp.task('build-css', function () {
    gulp.src(appDev + '**/*.scss', {base: "./"})
        .pipe(postcss([precss, autoprefixer, cssnano]))
        .pipe(ext_replace('.css'))
        .pipe(gulp.dest('./'));
});
2.扫描所有文件夹;缩小
.html
并将结果重命名为
.min.html

gulp.task('shrink-html',function(){
    return gulp.src(appDev+'**/*.html', {base: "./"})
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(ext_replace('.min.html'))
        .pipe(gulp.dest('./'));
});
我首先运行这些任务。一旦它们分别生成
.css
.min.html
,我就运行一个typescript编译器任务,将
.ts
转换为
.js

3最后我运行了SystemJS Builder任务。我使用
buildStatic
创建一个自执行捆绑包:

// build-ts is run before this, to compile typescript into JS
// and move everything out to the production folder (appProd)
gulp.task('bundle',['build-ts'], function() {
    var builder = new Builder('', './systemjs.config.js');

    return builder
        .buildStatic(appProd + '/main.js', appProd + '/bundle.js')
});
我知道在
buildStatic()
期间必须有一种缩小的方法,所以我不需要生成所有这些无用的
.css
.min.html
文件

我的最大努力:在处理文件时,我可以使用以下方法钩住文件:

我想缩小的文件名会打印到控制台上,我知道
fetch(file)
会给我它们的内容,但是如何处理内容并返回缩小的字符串呢

附言:

gulp.task('bundle',['build-ts'], function() {
    var builder = new Builder('', './systemjs.config.js');

    return builder
        .buildStatic(appProd + '/main.js', appProd + '/bundle.js', 
        {
            fetch: function (file, fetch) {
                if(file.name.search(/\/app.*\.html$/)!==-1){
                    console.log('html: '+ file.name);
                    //how to manipulate content and return minified HTML string?
                    return fetch(file);
                }else if (file.name.search(/\/app.*\.scss$/)!==-1){
                    console.log('scss: '+ file.name);
                    //how to manipulate content and return minified CSS string?
                    return fetch(file);
                }else{
                    return fetch(file);
                }                
            }
        });
});