简体   繁体   English

使用es6配置Grunt

[英]Grunt config with es6

It is possible to write grunt config files in es6 like this? 可以像这样在es6中编写grunt配置文件吗?

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

One possible way to do this painlessly is to use Babel's babel-register module like this: 一种可能的方法是无痛地使用Babel的babel-register模块,如下所示:

Installation: 安装:

npm install babel-register --save-dev

.babelrc: .babelrc:

{
    presets: ["es2015"]
}

Gruntfile.js: Gruntfile.js:

require('babel-register')

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

Gruntfile.es Gruntfile.es

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

GruntJS is a javascript based application. GruntJS是一个基于JavaScript的应用程序。 It runs under the node/iojs process and adheres to the capabilities of that environment. 它在node / iojs进程下运行,并且遵循该环境的功能。 If you use iojs or a node version that supports these features, then yes, its possible. 如果您使用iojs或支持这些功能的节点版本,那么是的,它可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM