如何使用Gruntfile.ls(livescript Grunt)

时间:2014-04-03 21:28:36

标签: gruntjs livescript

我想用lifecript写我的Gruntfile.js

我已完成Gruntfile.jsGruntfile.coffee这两项工作都是开箱即用的

Gruntfile.ls应该有效......对吗?

我在网上看过一些Gruntfile.ls或者是否需要编译(除了.coffee版本)?

的LiveScript

(调用$ grunt时出错)

A valid Gruntfile could not be found. Please see the getting started guide for
more information on how to configure grunt: http://gruntjs.com/getting-started
Fatal error: Unable to find Gruntfile.

Gruntfile.ls

#global module:false

module.exports = (grunt) ->

  # Project configuration.
  grunt.init-config {}=

    meta:
      version: \0.0.1

    livescript:
      src:
        files:
          "build/js/main.js": "src/scripts/main.ls"

    watch:
     livescript:
        files: <[src/scripts/**/*.ls]>
        tasks: <[livescript]>
        options: {+livereload}

  # load tasks
  grunt.loadNpmTasks \grunt-livescript
  grunt.loadNpmTasks \grunt-contrib-watch

  # register tasks
  grunt.registerTask \default, <[livescript]>

编译:

(在致电$ grunt时运作)

Gruntfile.js

module.exports = function(grunt){
  grunt.initConfig({
    meta: {
      version: '0.0.1'
    },
    livescript: {
      src: {
        files: {
          "build/js/main.js": "src/scripts/main.ls"
        }
      }
    },
    watch: {
      livescript: {
        files: ['src/scripts/**/*.ls'],
        tasks: ['livescript'],
        options: {
          livereload: true
        }
      }
    }
  });
  grunt.loadNpmTasks('grunt-livescript');
  grunt.loadNpmTasks('grunt-contrib-watch');
  return grunt.registerTask('default', ['livescript']);
};

2 个答案:

答案 0 :(得分:2)

将此用作Gruntfile.js

require('LiveScript');

module.exports = function (grunt) {
    require('./Gruntfile.ls')(grunt);
}

需要来自npm的LiveScript包。

答案 1 :(得分:0)

我更喜欢将主Gruntfile保存在js中,而将任务保存在ls。

示例设置:

require("LiveScript")
module.exports = function(grunt){
  require('load-grunt-tasks')(grunt) // autoload npmtasks from package.json
  require('load-grunt-config')(grunt) // lets you keep each task in separate file
}

实际上,我使用位于https://github.com/wolfflow/load-grunt-config/tree/beta/0.8.0

load-grunt-config分叉

如果您想尝试一下,只需将以下字符串添加到您的package.json文件中:

"load-grunt-config": "git://github.com/wolfflow/load-grunt-config.git#beta/0.8.0"

然后运行npm install