Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grunt tmod时报错 #5

Open
tianzhiqing opened this issue Aug 8, 2014 · 3 comments
Open

grunt tmod时报错 #5

tianzhiqing opened this issue Aug 8, 2014 · 3 comments

Comments

@tianzhiqing
Copy link

求解!
Warning: Cannot read property '0' of undefined Use --force to continue.
Aborted due to warnings.
tmod: {
template: {
src: './tpl/*.html',
dest: './dist/template.js',
options: {
//base: './src'
}
}
}

@piaoluoya
Copy link

我也遇到了这个问题
环境:
系统ox 10.9
nodeJs是v0.10.30
grunt配置
package.json的全部

    {
      "name": "todo",
      "version": "0.1.0",
      "author": "ply",
      "devDependencies": {
        "grunt": "0.x.x",
        "grunt-contrib-concat": "*",
        "grunt-contrib-copy": "*",
        "grunt-contrib-cssmin": "*",
        "grunt-contrib-jshint": "*",
        "grunt-contrib-uglify": "*",
        "grunt-contrib-watch": "*",
        "grunt-tmod": "^1.0.0"
      }
    }

Gruntfile.js的部分

    //模版
    tmod: {
        template: {
            src: 'src/html/**/*.html',
            dest: 'dist/template.js',
            options: {
                base: 'src/html'
            }
        }
    },

    //自动监听指定事件,然后自动运行指定的任务
    watch: {
        //复制框架插件源文件和图片
        copyFile: {
            files: ['src/img/**','src/lib/**'],
            tasks: ['copy'],
            options: {
                spawn: false,
                //event: ['added', 'deleted','changed']
                livereload: true
            }
        },
        //编译模版
        template: {
            files: '<%=tmod.template.src%>',
            tasks: ['tmod'],
            options: {
                spawn: false
                //livereload: true
            }
        }

    }

修改文件时提示:

    Running "watch" task
    [D] Task source: /usr/www/piaoluoya/todo/node_modules/grunt-contrib-watch/tasks/watch.js
    Waiting...
    >> File "src/html/t.html" changed.

    Running "tmod:template" (tmod) task
    [D] Task source: /usr/www/piaoluoya/todo/node_modules/grunt-tmod/tasks/tmod.js
    Warning: Cannot read property '0' of undefined
    Running "watch" task
    [D] Task source: /usr/www/piaoluoya/todo/node_modules/grunt-contrib-watch/tasks/watch.js
    Waiting...

@piaoluoya
Copy link

纠结一半天,认真看了grunt-tmod模块中的说明文档,我问题已经解决了。解决方法如下

    //模版
    tmod: {
        template : {
            files: [{
                src: 'src/html'
            }],
            options: {
                debug : false,
                charset : "utf-8",
                type: "templatejs",
                dest: '../../dist' //此路径是相对files中的src目录
            }
        }
    },

    //自动监听指定事件,然后自动运行指定的任务
    watch: {
        //编译模版
        tmod: {
            files: ['src/html/**/*.html'],
            tasks: ['tmod'],
            options: {
                spawn: false
                //livereload: true
            }
        }

    }

@tianzhiqing
Copy link
Author

谢谢 @piaoluoya 看了你的答案,问题解决了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants