首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >作为源的GruntJS glob

作为源的GruntJS glob
EN

Stack Overflow用户
提问于 2014-07-16 23:48:13
回答 1查看 65关注 0票数 1

我有一个很大的数组,比如

代码语言:javascript
运行
复制
[ { src:
   [ './src/branding/appLogo/template.hbs',
     './src/buttons/append/template.hbs',
     './src/buttons/button/template.hbs',
     './src/buttons/clean/template.hbs',
     './src/buttons/clear/template.hbs',
     './src/buttons/danger/template.hbs',
     './src/buttons/default/template.hbs',
     './src/buttons/disabled/template.hbs',
     './src/buttons/large/template.hbs',
     './src/buttons/link/template.hbs',
     './src/buttons/primary/template.hbs',
     './src/buttons/small/template.hbs',
     './src/buttons/success/template.hbs',
     './src/documentation/technology-overview/template.hbs',
     './src/forms/checkbox/template.hbs',
     './src/forms/fieldAppend/template.hbs',
     './src/forms/fieldDefault/template.hbs',
     './src/forms/fieldError/template.hbs',
     './src/forms/fieldPrepend/template.hbs',
     './src/forms/fieldPrependAppend/template.hbs',
     './src/forms/radioButton/template.hbs',
     './src/forms/select/template.hbs',
     './src/forms/textarea/template.hbs',
     './src/icons/appSwitch/template.hbs',
     './src/modules/alerts/template.hbs',
     './src/modules/attributions/template.hbs',
     './src/modules/avatar/template.hbs',
     './src/modules/beacon/template.hbs',
     './src/modules/d3DonutChart/template.hbs',
     './src/navigation/appSwitcher/template.hbs',
     './src/navigation/avatarDropdown/template.hbs',
     './src/navigation/contextMenu/template.hbs',
     './src/navigation/headerMenu/template.hbs',
     './src/navigation/paginate/template.hbs',
     './src/prototypes/home/template.hbs',
     './src/structures/form/template.hbs',
     './src/structures/header/template.hbs',
     './src/typography/blockquote/template.hbs',
     './src/typography/floats/template.hbs',
     './src/typography/headers/template.hbs',
     './src/typography/hidden/template.hbs',
     './src/typography/hr/template.hbs',
     './src/typography/hrText/template.hbs',
     './src/typography/lists/template.hbs',
     './src/typography/paragraph/template.hbs',
     './src/typography/pre/template.hbs',
     './src/typography/table/template.hbs',
     './src/typography/tags/template.hbs',
     './src/utilities/extends/template.hbs',
     './src/utilities/keyframes/template.hbs',
     './src/utilities/mixins/template.hbs',
     './src/utilities/svgFilterPieShrink/template.hbs',
     './src/utilities/svgFilterSubtleDropShadow/template.hbs' ],
  dest: './build/scripts/handlebars.js' } ]

我想渲染所有这些handlebars模板,它们都应该在一个文件中结束。

代码语言:javascript
运行
复制
module.exports = (grunt) ->
  config = grunt.file.readJSON("config.json")
  hbsGlob = ''
  grunt.task.loadTasks('./tasks')
  grunt.option('config', config)

  grunt.initConfig
    pkg: grunt.file.readJSON("package.json")

    handlebars:
      options:
        namespace: 'Guide'
        processName: (path) ->
          return path.replace('.js', '').replace('/', '.') + '.template'

      guide:
        files:
          @hbsGlob


  grunt.registerTask 'etch-scripts', =>
    glob = grunt.option('filteredGlob')
    glob.push "!./src/**/*.{md,js,json}"

    options =
      rename: (dest, matchedSrcPath, options) ->
        return dest

    @hbsGlob = grunt.file.expandMapping(glob,  config.build + '/scripts/handlebars.js', options)

    grunt.task.run 'handlebars:guide'

  grunt.loadNpmTasks('grunt-contrib-handlebars');

我得到的唯一输出是

代码语言:javascript
运行
复制
Running "handlebars:guide" (handlebars) task
>> 0 files created.

Done, without errors.

你知道哪里出了问题吗?这样我就可以使用这个glob作为src/dest.

EN

回答 1

Stack Overflow用户

发布于 2014-07-17 04:27:03

在对此进行了大量研究后,我发现了一个小小的替代方案,它最终完美地工作了!

设置hbsGlob变量后,我将该变量添加到Grunt配置grunt.config.set('hbsGlob', @hbsGlob)

然后在handlebars中:guide task,我将其设置为

代码语言:javascript
运行
复制
guide:
  files: '<%= hbsGlob %>'

一切都完美地构建起来了!

编辑--来源:https://stackoverflow.com/a/14780870/399742

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24785176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档