【问题标题】:How to manage and concat CoffeeScript files with Grunt/Yeoman?如何使用 Grunt/Yeoman 管理和连接 CoffeeScript 文件?
【发布时间】:2012-12-18 08:42:52
【问题描述】:

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

scripts/
  lib/
    ...
  common/
    ...
  util/
    ...
  app/
    views/
    models/
      A.cofffee
      B.cofffee
      C.cofffee

我想按特定顺序连接它们并编译成一个文件。

所以我想说“按这个顺序编译”

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/*

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

【问题讨论】:

    标签: coffeescript gruntjs yeoman


    【解决方案1】:

    在您的GruntFile.js 中,您应该有一个coffee 步骤,例如:

    // Coffee to JS compilation
    coffee: {
      compile: {
        files: {
          'temp/scripts/*.js': 'app/scripts/**/*.coffee' 
        },
        options: {
          basePath: 'app/scripts'
        }
      }
    },
    ...
    

    通常,您应该能够做到:

        files: {
          '/path/to/destination/index.js': [
            'scripts/lib/some_superclass.coffee', 
            'scripts/lib/**/*.coffee', 
            'common/**/*.coffee',
            #...
          ] 
        },
    

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 2014-10-09
      • 2014-07-22
      • 2012-12-14
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多