javascript - grunt-include-source 多个配置

标签 javascript gruntjs

我的问题如下;我正在使用 grunt-include-source ( https://www.npmjs.com/package/grunt-include-source ) 将我的脚本和 css 包含到我的 index.html 中,这工作正常,但我只能指定一个基本路径,我想为 dev 和 dev 设置此插件生产。 (我使用相同的文件夹结构,因此我的 index.html 中不会发生任何变化,唯一的区别是在我的作品中串联)

 includeSource: {
  options: {
    basePath: 'dev'
  },
  myTarget: {
    files: {
      'dev/index.html': 'app/index.html'
    }
  }

},

上面的代码工作正常,现在我想要有 2 个不同的配置,但是在运行任务 includeSource:dev: 时这样的东西不起作用:

 includeSource: {
  dev: {
    options: {
      basePath: 'dev'
     },
     myTarget: {
      files: {
      'dev/index.html': 'app/index.html'
      }
     }
   },
   prod: {
    options: {
      basePath: 'prod'
     },
     myTarget: {
      files: {
      'prod/index.html': 'app/index.html'
      }
     }
   }
},

index.html:

 <!-- include: "type": "js", "files": "scripts/*.js" -->

有人可以帮助我如何实现这一目标吗?

编辑:为了更清楚一点,我在生产或开发构建完成后运行此脚本,对于我的产品/开发,所有脚本都存储在scripts/中

亲切的问候,

G

最佳答案

只需像这样配置您的任务即可:

includeSource: {
  options: {
    basePath: 'dev/'
  },
  dev: {
    files: {
      'dev/index.html': 'app/index.html'
    }
  },
  prod: {
    options: {
      basePath: 'dist/'
    },
    files: {
      'dist/index.html': 'app/index.html'
    }
  }
},

关于javascript - grunt-include-source 多个配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29676897/

相关文章:

javascript - d3有没有类似jQuery.closest(selector)的api?

css - 如何更改 less 编译,使其不添加 @import 语句?

angularjs - 如何在useminPrepare中为HTML文件中的每个 block 定义单独的流程?

node.js - 错误 Mocha 不支持 Node 5.5.x

javascript - grunt 连接端口选项被忽略

javascript - 对浮点相等性测试感到困惑?

javascript - 如何在 ngCookies 中设置 httpOnly 标志?

javascript - 在 _.map() 中使用异步函数

javascript - 带有正则表达式的 grunt glob 文件?

javascript - 在 html 表的一列中合并 <td> 行