lichunqiang / gulp-tmod

grunt-tmod gulp version
31 stars 8 forks source link

不生效,哪里错了? #4

Open liyatang opened 9 years ago

liyatang commented 9 years ago

你好,使用 gulp-tmod 中遇到了点问题,求指导。

我这样用是ok的

gulp.task('mobile-tmod', function () {
    return gulp.src(['./mobile/tpl/*.html', './mobile/tpl/**/*.html']).
        pipe(tmodjs({
            base: './mobile/tpl',
            output: './mobile/tpl/build'
        }));
});

image

问题来了...

然后我要使用watch。 完全按照readme的使用哦。

gulp.task('mobile-tmod-watch', function () {
    return gulp.src(['./mobile/tpl/*.html', './mobile/tpl/**/*.html']).
        pipe(watch(function (files) {
            files.pipe(tmodjs({
                base: './mobile/tpl',
                combo: true,
                output: './mobile/tpl/build'
            }));
        }));
});

然后就报bug了

image

从提示上来看是gulp-watch 的参数问题,于是修正如下(给watch加了第一个参数)。

gulp.task('mobile-tmod-watch', function () {
    return gulp.src(['./mobile/tpl/*.html', './mobile/tpl/**/*.html']).
        pipe(watch(['./mobile/tpl/*.html', './mobile/tpl/**/*.html'], function (files) {
            files.pipe(tmodjs({
                base: './mobile/tpl',
                combo: true,
                output: './mobile/tpl/build'
            }));
        }));
});

还是有错误

image

然后我看了官网(https://github.com/floatdrop/gulp-watch)gulp-watch的用法,改为

gulp.task('mobile-tmod-watch', function () {
    return gulp.src(['./mobile/tpl/*.html', './mobile/tpl/**/*.html']).
        pipe(watch(['./mobile/tpl/*.html', './mobile/tpl/**/*.html'])).
        pipe(plugins.tmod({
            base: './mobile/tpl',
            output: './mobile/tpl/build'
        }));
});

没有报错

image

可是我修改模板,并没有执行编译

求助,我应该怎么写

lichunqiang commented 9 years ago

问题解决没?

liyatang commented 9 years ago

多谢关注。问题还没有解决,求指导。 我Q 531059158

thethreeonee commented 9 years ago

同样的问题,现在只好用 tmod 的命令行来监视并 build

lichunqiang commented 9 years ago

不好意思,工作原因不在使用tmod了,对于目前碰到的问题暂时没有精力去解决,如果大家能解决问题可以提pr。

抱歉!

que01 commented 9 years ago

我也遇到这个问题,目前写的是这样子:

gulp.watch([path.join(tpl.src, '*/.html')]).on('change', function (event) {
if (event.type === 'changed') { console.log("动态编译模板...",event.path); gulp.src(event.path) .pipe($.tmod({ base: tpl.src, combo: true, cache:false, type:"cmd", output: tpl.dist })) } });

改动之后有监视到变化 也有执行操作,但是编译就是失败了。。。我也没看出来问题到底在哪儿

dashixiong1990 commented 9 years ago

我看了下tmod的源码 它自己带有watch功能 可看https://github.com/aui/tmodjs/blob/master/bin/tmod#L207 不明白作者为啥没加 我把这行代码加到作者的gulp插件里边去(注意加到生成的tmod实例后面) 亲测可用 不过这样就直接开启了实时监控的功能了 可以在option里加一个参数用来控制是否开启