Is it possible write a gulpfile in es6?

前端 未结 6 2060
终归单人心
终归单人心 2020-12-23 09:52

Question: How can I write my gulp file in ES6 so I can use import instead of require and use => syntax over

6条回答
  •  天命终不由人
    2020-12-23 10:05

    I use babel-node and native gulp.

    1. Install babel and gulp as devDependencies.
    2. Write gulpfile.js with ES6 syntax.
    3. Use command ./node_modules/.bin/babel-node ./node_modules/.bin/gulp to run gulp
    4. In package.json scripts section, you can skip the first ./node_modules/.bin/ part - as babel-node ./node_modules/.bin/gulp.

    The advantage of this appoach is, one day when the node.js support all ES6 features one day, all you need to opt-out babel runtime is to replace babel-node with node. That is all.

提交回复
热议问题