Babel转换es7类装饰器意外的令牌错误

Fis*_*ers 5 babel transpiler ecmascript-6 aurelia ecmascript-7

我正在使用一个使用es6和es7代码的Aurelia应用程序,我试图使用babel来转换代码.我在packages.json文件中有以下内容

"scripts": {
    "babel": "babel --stage 1 -d AureliaWeb/ ../Test/Aurelia/ --extends babelrc",
Run Code Online (Sandbox Code Playgroud)

我安装了以下软件包:

"devDependencies": {
"babel-core": "^6.10.4",
"babel-plugin-syntax-decorators": "^6.8.0",
"babel-plugin-syntax-flow": "^6.8.0",
"babel-plugin-transform-es2015-modules-amd": "^6.8.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.10.3",
"babel-plugin-transform-es2015-modules-systemjs": "^6.9.0",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-es2015-loose": "^7.0.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.5.0",
"babel-preset-stage-1": "^6.5.0",
"babel-preset-stage-2": "^6.11.0",
"babel-preset-stage-3": "^6.11.0",
"babel-register": "^6.9.0",
"chai": "^3.5.0"
},
"dependencies": {
"babel-plugin-transform-class-properties": "^6.10.2",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015-loose": "^7.0.0",
"core-js": "^2.4.0",
"lodash": "^4.13.1"
}
Run Code Online (Sandbox Code Playgroud)

我试图转换es7代码看起来像:

import {inject, noView} from 'aurelia-framework';
import {HttpClient} from 'aurelia-http-client';

@noView() <-- THIS IS CAUSING THE ERROR!!
@inject(HttpClient)
export class CompanyDataManager {
Run Code Online (Sandbox Code Playgroud)

我得到错误语法错误意外令牌引发类装饰器@noView.我检查了第1阶段预设,我知道已经删除了类装饰器http://babeljs.io/docs/plugins/preset-stage-1/

由于这个原因,我在遗留装饰中添加了'babel-plugin-transform-decorators-legacy here'https:// https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy

所以我的.babelrc(位于我项目的根目录)看起来像这样:

{
  "presets": [ "es2015-loose", "stage-1" ],
  "plugins": [
    "syntax-decorators",
    "syntax-flow",
    "babel-plugin-transform-decorators-legacy",
    "transform-class-properties",
    "transform-flow-strip-types"
  ]
}   
Run Code Online (Sandbox Code Playgroud)

但是我仍然没有找到快乐!问题是

  1. 当我在npm中执行babel脚本时,如何确认我的babelrc文件被拾取?我尝试添加--extends babelrc以试图强制它,但我不确定这是否正确.
  2. 我也试过在babel命令中指定一个插件,如下所示:

    "babel --plugins babel-plugin-transform-decorators-legacy --stage 1 -d AureliaWeb/../Test/Aurelia/"

仍然没有运气,任何帮助将不胜感激.

更新1

在搞乱.bablerc文件之后,我想我可能把它放在了错误的位置.我的结构如下(它是一个mvc应用程序).

  • Test.UnitTest(Project)< - 我从这里运行babel脚本
    • AureliaWeb < - end trandpiled location
  • 测试(项目)
    • Aurelia < - 包含实际的Aurelia代码

将.bablerc文件移动到Test> Aurelia后,我开始收到以下错误

"C:\ Code\src\Test\Aurelia\.babelrc"中指定的未知插件"transform-decorators-legacy"为0,尝试解析相对于"C:\ Code\src\Test\Aurelia"

我已经尝试在两个项目中为transform-decorators-legacy安装包,看看它是否有所不同

更新2

我现在可以确认这实际上是问题,看起来babel文件需要放在源文件夹中,而不是目的地或者执行babel的位置.

Fis*_*ers 0

我已经回答了我自己的问题,详细信息在主帖子中。

babel 文件需要放置在源文件夹中,而不是目标文件夹或执行 babel 的位置。