I
I
inlinerjs2015-06-19 23:19:57
css
inlinerjs, 2015-06-19 23:19:57

How to collect html templates from mustache using gulp?

Previously, I did not work with build systems. I'm using Sass/Compass-watch/Mustache for Ruby. I'm tired of a very slow build (more than 6 seconds), I want to switch to gulp build. The assembly and watcher for sass work fine, but I can’t figure it out with mustache.
gulpfile.js

var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var mustache = require("gulp-mustache-plus");

// Gulp Sass Task 
gulp.task('sass', function() {
  gulp.src('./scss/{,*/}*.{scss,sass}')
    .pipe(sourcemaps.init())
    .pipe(sass({
      errLogToConsole: true
    }))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('./css'));
});

// Gulp Mustache Task 
gulp.task('mustache', function() {
    gulp.src("./templates/*.mustache")
        .pipe(mustache({},{},{
            file_1: "partials/*.mustache"
        })).pipe(gulp.dest("./"));
});

gulp.task('default', ['sass', 'mustache'], function () {
    gulp.watch('./scss/{,*/}*.{scss,sass}', ['sass']);
    gulp.watch('./templates/{,*/}*.{mustache}', ['mustache']);
});

The file structure is like this:
.
├── css
├── scss
├── index.html
├── gulpfile.js
└── templates
    ├── index.mustache
    └── partials
        └── header.mustache

Those. templates/index.mustache should compile to index.html
index.mustache:
{{> partials/head }}

<body>
    {{> partials/header }}

    <div class="wrap">
        {{> some_inner_partial }}

        <div class="content">
            ...
        </div>
    </div>

    {{> partials/footer }}

</body>
</html>

As a result, only tags are compiled into html, but not parshals. And the watcher does not work, i.e. nothing happens when changing any mustache file. Collected only when gulp is run.
What needs to be fixed in gulpfile.js? I am using the gulp-mustache-plus
plugin . Is there a better plugin for my task?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2015-06-19
@inlinerjs

gulp.src("./templates/ **/ *.mustache")
and
gulp.watch('./templates/ **/*. mustache', ['mustache']);
So have you tried it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question