Jsonzhang / grunt-tmod

a grunt plugin for tmodjs
MIT License
27 stars 17 forks source link

自定义函数预编译后的文件里面没了 #6

Open tianzhiqing opened 10 years ago

tianzhiqing commented 10 years ago

我还只做一个demo,代码如下
index.html

aa{{tag}}
cc{{time | dateFormat:'yyyy年 MM月 dd日 hh:mm:ss'}}

预编译后 index.js template('confirmOrder/index',function($data,$id) { var $helpers=this,$escape=$helpers.$escape,tag=$data.tag,$out='';$out+='

aa'; $out+=$escape(tag); $out+='
cc
'; return new String($out); }); 貌似那个函数被干掉了

piaoluoya commented 10 years ago

我也遇到这个问题了,你怎么解决的?

tianzhiqing commented 10 years ago

@piaoluoya

我的解决办法是没有用这grunt-tmodjs脚本,具体实现如下

1、 安装tmodJS npm install -g tmodjs 2、grunt里引入安装 grunt-shell 模块,再通过shell脚本的方式调用tomodjs,具体代码如下

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    shell: {
        options: {
            stdout: true
        },

        watchXtpl: {
            command: 'tmod ./src/mods --output ./src/tpl'
        },

        buildXtpl: {
            command: 'tmod ./src/mods --output ./src/tpl --no-watch'
        }
    }
})
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('tpl', ['shell:watchXtpl']);
piaoluoya commented 10 years ago

谢谢了,我的问题也是没有用grunt-tmodjs 才解决的。