我正在尝试使用类将我的现有Angular应用程序转换为ES6。但是当eslint遇到import/export语句时,它会在编译我的js文件时失败。
class HeaderController {
constructor($rootScope, $scope) {
this.$rootScope = $rootScope;
this.$scope = $scope;
}
changeNavItem(selectedTab) {
this.activeNavItem = selectedTab;
}
init() {
this.activeNavItem = 'All';
} }
HeaderController.$inject = ['$rootScope', '$scope'];
angular.module('app')
.controller('HeaderController', HeaderController);
export default HeaderController; // fails on this line
ESlint抛出错误:“由于解析错误无法处理源代码 'import' 和 'export' 只能与 'sourceType: module' 一起使用”。
我已经添加了ESlint所需的配置,但仍然失败。
我在我的eslintrc.json中添加了以下内容:
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"allowImportExportEverywhere": true,
"ecmaFeatures": {
"modules": true,
"arrowFunctions": true,
"classes": true
}
}
请帮忙解决这个问题,如果有一个完整的使用gulp在angular中设置es6的例子,那将非常有帮助。