3

我想以与使用 use-min 添加 js 相同的方式将模板添加为 JS 缓存。问题是 use-min 不允许在开箱即用的 use-min 步骤中添加任意内容。

4

1 回答 1

2

的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>

*(占位符的原因是似乎 use-min 读取输入文件而不是输出文件来确定类型)

吞咽任务:

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$');
    }
});
于 2015-05-26T12:14:46.133 回答