如何使用Grunt/Yeoman管理和连接CoffeeScript文件?

hak*_*nin 1 coffeescript gruntjs yeoman

我是Grunt/Yeoman的新手,我有一个现有的应用程序,有40多个Coffeescript文件,如下所示:

scripts/
  lib/
    ...
  common/
    ...
  util/
    ...
  app/
    views/
    models/
      A.cofffee
      B.cofffee
      C.cofffee
Run Code Online (Sandbox Code Playgroud)

我想以特定的顺序连接它们并编译成一个文件.

所以我想说"按此顺序编译"

scripts/lib/some_superclass.coffee
scripts/lib/*
common/*
util/app/views/*
util/app/models/some_model_that_needs_to_be_required_first.coffee
util/app/models/*
Run Code Online (Sandbox Code Playgroud)

Grunt/Yeoman项目如何解决这个问题?(我真的不想拼出每个文件)

asg*_*oth 7

在你的GruntFile.js,你应该有一个coffee步骤:

// Coffee to JS compilation
coffee: {
  compile: {
    files: {
      'temp/scripts/*.js': 'app/scripts/**/*.coffee' 
    },
    options: {
      basePath: 'app/scripts'
    }
  }
},
...
Run Code Online (Sandbox Code Playgroud)

通常,您应该能够:

    files: {
      '/path/to/destination/index.js': [
        'scripts/lib/some_superclass.coffee', 
        'scripts/lib/**/*.coffee', 
        'common/**/*.coffee',
        #...
      ] 
    },
Run Code Online (Sandbox Code Playgroud)