[英]grunt babel is not working
我試圖將es6轉換為es5,但它無法正常工作。
我的Gruntfile.js
module.exports = function(grunt){
"use strict";
grunt.loadNpmTasks('grunt-babel');
grunt.initConfig({
"babel": {
options: {
sourceMap: true
},
dist: {
files: {
"dist/app.js": "app.js"
}
}
}
});
grunt.registerTask("default", ["babel"]);
}
當我運行grunt時,文件dist / app.js與app.js相同
有什么問題嗎?
我發現了錯誤。
我不得不安裝babel-preset-es2015: npm install -D babel-preset-es2015
並在package.json中配置babel。
{
"name": "babel",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"babel": {
"presets": [
"es2015"
]
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.1.18",
"babel-preset-es2015": "^6.1.18",
"babelify": "^7.2.0",
"grunt": "^0.4.5",
"grunt-babel": "^6.0.0",
"grunt-browserify": "^4.0.1",
"grunt-contrib-watch": "^0.6.1",
"load-grunt-tasks": "^3.3.0"
}
}
你必須創建一個文件名.babelrc,並在文件中你必須寫這些:
{
'presets':['es2015']
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.