问题
It is possible to write grunt config files in es6 like this?
//Gruntfile.js
module.exports = function (grunt) {
var arr = [1,2,3];
arr.forEach(val => {
...
});
...
}
回答1:
One possible way to do this painlessly is to use Babel's babel-register
module like this:
Installation:
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({})
}
回答2:
GruntJS is a javascript based application. It runs under the node/iojs process and adheres to the capabilities of that environment. If you use iojs or a node version that supports these features, then yes, its possible.
来源:https://stackoverflow.com/questions/31668870/grunt-config-with-es6