Grunt config with es6

Deadly 提交于 2019-12-23 08:57:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!