【问题标题】:grunt-contrib-jade compiling to single JS with cwdgrunt-contrib-jade 使用 cwd 编译为单个 JS
【发布时间】:2015-05-21 13:11:09
【问题描述】:

我正在尝试使用 grunt-contrib-jade 将多个玉模板编译成单个 JS 文件。我面临的问题是,使用模板的完整路径,我会得到具有完整路径的函数名称。我想避免这种情况,所以我尝试使用 cwd (不展开)。结果如下:

>> Source file "test.jade" not found.
>> Source file "test2.jade" not found.

有什么方法可以实现我的计划吗?我对该任务的 grunt 配置如下:

jade: {
  js: {
    options: {
      client: true,
      amd: true
    },
    files: [ {
      cwd: 'js/views/',
      src: ['*.jade'],
      dest: 'js/tmp/templates.js'
    } ]
  }
},

感谢您的建议, 德拉科

【问题讨论】:

  • 据我所知grunt-contrib-jade 不合并
  • 确实如此;)。它适用于以下配置,只有完整路径作为函数名称:files: [ { src: 'js/views/*.jade', dest: 'js/tmp/templates.js' } ]
  • 这很奇怪。我试过了,但它不起作用。也许,我做错了什么。这就是我的配置的样子 output.jsbin.com/tobute/1.js
  • 因为expand: true,grunt 为每个文件单独运行jade,这意味着你最终会得到多个文件。但是,如果您将其删除,最终会带来我发布的错误:(。

标签: gruntjs pug


【解决方案1】:

愚蠢的我,没有完全阅读插件的文档:(。

解决方案很简单,使用processName 选项:

options: {
      client: true,
      amd: true,
      processName: function(path) {
        var pathChunks = path.split('.')[0].split('/');
        return pathChunks[pathChunks.length - 1];
      }
    }

【讨论】:

    猜你喜欢
    • 2013-05-05
    • 1970-01-01
    • 2013-08-08
    • 2013-07-21
    • 2014-02-25
    • 1970-01-01
    • 2018-08-11
    • 2013-07-22
    • 2016-09-04
    相关资源
    最近更新 更多