gruntjs - 使用 es6 进行 Grunt 配置

标签 gruntjs ecmascript-6

可以像这样在 es6 中编写 grunt 配置文件吗?

//Gruntfile.js
module.exports = function (grunt) {
  var arr = [1,2,3];
  arr.forEach(val => {
    ...
  });
  ...
}

最佳答案

一种无痛的方法是使用 Babel 的 babel-register像这样的模块:

安装:
npm install babel-register --save-dev
.babelrc:

{
    presets: ["es2015"]
}

Gruntfile.js:
require('babel-register')

module.exports = require('./Gruntfile.es').default

Gruntfile.es
export default function(grunt) {
    grunt.initConfig({})
}

关于gruntjs - 使用 es6 进行 Grunt 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31668870/

相关文章:

javascript - 对于本地模块,Grunt 失败并显示 "Cannot find module"

javascript - 如何使用 gruntjs 缩小 css

node.js - Windows 上的 Jenkins + Grunt = 持续的 EBUSY 和 ENOENT 错误

javascript - 当使用对象作为映射时,它的键总是转换为字符串。为什么?

reactjs - blueprintjs 选择组件 onItemSelect 函数不运行

javascript - 在哪里/如何为我自己创建的表单(Vue)组件定义提交目的地?

嵌套数组的 Javascript 数组重组

javascript - 为什么 promise 链不能按预期工作(链接任务)

javascript - Grunt 将 Angular ui 路由器模板连接到一个文件中

testing - http-server 阻止 travis CI 上的脚本