How do you use gulp - angular-templatecache with gulp-usemin

I want to add templates as a JS cache the same way you add js using use-min. The problem is that use-min doesn't allow you to add arbitrary content in the use-min sequence out of the box.

+3


source to share


1 answer


html:

<!-- build:jslib assets/js/lib.js -->
<script src="bower_components/bower-stuff/some.js"></script>
<!-- endbuild -->

<!-- build:js assets/js/app.js -->
<script src="assets/app/main.js"></script>
<script src="assets/app/config.js"></script>
<script src="assets/app/routes.js"></script>
<!-- endbuild -->

<!-- build:templateCache assets/js/templateCache.js -->
<script src="assets/app/templateCachePlaceholder.js"></script>
<!-- endbuild -->
</body>
</html>

      

* (the reason for the placeholder is that it seems that use-min reads input files, not output files, to determine the type)



Gulp task:

gulp.task('build', ['bower', 'compass'], function () {
    return gulp.src(
        [
            'frontend-src/index.html',
            'frontend-src/config/**/*',
            'frontend-src/assets/img/**/*',
            'frontend-src/assets/fonts/**/*',
            'frontend-src/assets/translations/*'
        ],
        {base: 'frontend-src/'})
        .pipe(plugins.if(isIndexHtml, plugins.usemin({
            js: [plugins.ngAnnotate(), plugins.uglify(), plugins.rev()],
            jslib: [plugins.rev()],
            css: [plugins.minifyCss(), 'concat', plugins.rev()],
            templateCache: [
                plugins.addSrc('frontend-src/assets/app/**/*.html'),
                plugins.angularTemplatecache({
                    module: ANGULARJS_MODULE_NAME,
                    root: 'assets/app/'
                }),
                'concat',
                plugins.rev()
            ]
        })))
        .pipe(gulp.dest('frontend-prod/'));

    function isIndexHtml (file) {
        return file.path.match('index\\.html$');
    }
});

      

+2


source







All Articles