我如何写不修饰语法angular2? [英] How do I write angular2 without decorator syntax?
本文介绍了我如何写不修饰语法angular2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我大致如下的JavaScript /的打字稿为 Angular2
写我的应用程序在 ES6
,但不能得到decoractor到作品
I'm roughly following JavaScript/TypeScript quickstart for Angular2
to write my app in ES6
but can't get the decoractor to works
import * as stylesheet from '../assets/styles/app.scss';
import jQuery from '../node_modules/jquery/dist/jquery';
import $ from '../node_modules/jquery/dist/jquery';
import * as semanticUi from '../node_modules/semantic-ui/dist/semantic';
import '../node_modules/angular2/bundles/angular2-polyfills'
import '../node_modules/rxjs/bundles/Rx.umd'
import '../node_modules/angular2/bundles/angular2-all.umd'
import {bootstrap} from '../node_modules/angular2/bootstrap'
import {AppComponent} from './app.component'
bootstrap(AppComponent);
的 app.component.js 的
import {Component} from '../node_modules/angular2/core';
@Component({
selector: 'my-app',
template: '<h1>Hello {{ name }}</h1>'
})
export class AppComponent {
constructor() {
this.name = 'Max';
console.log(this.name);
}
}
的的package.json 的
{
"scripts": {
"build:app": "browserify -e ./app/index.js -o ./dist/app.js",
},
"devDependencies": {
"babel-core": "6.3.x",
"babel-plugin-angular2-annotations": "^3.0.3",
"babel-plugin-transform-decorators": "^6.3.13",
"babel-preset-es2015": "6.3.x",
"babelify": "7.2.x",
"cpy": "3.4.x",
},
"babel": {
"presets": [
"es2015"
],
"plugins": [
"angular2-annotation",
"transform-decorators"
]
},
"browserify": {
"transform": [
[
"babelify",
{
"presets": [
"es2015"
],
"plugins": [
"angular2-annotation",
"transform-decorators"
]
}
]
]
}
}
错误
npm run build:app
> ng2-app@0.0.2 build:app /data/projects/ng2-app
> browserify -e ./app/index.js -o ./dist/app.js
ReferenceError: Unknown plugin "angular2-annotation" specified in "/data/projects/ng2-app/package.json" at 0, attempted to resolve relative to "/data/projects/ng2-app" while parsing file: /data/projects/ng2-app/app/index.js
at /data/projects/ng2-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:193:17
at Array.map (native)
at Function.normalisePlugins (/data/projects/ng2-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:173:20)
at OptionManager.mergeOptions (/data/projects/ng2-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:271:36)
at OptionManager.addConfig (/data/projects/ng2-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:221:10)
at OptionManager.findConfigs (/data/projects/ng2-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:370:30)
at OptionManager.init (/data/projects/ng2-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:412:12)
at File.initOptions (/data/projects/ng2-app/node_modules/babel-core/lib/transformation/file/index.js:191:75)
at new File (/data/projects/ng2-app/node_modules/babel-core/lib/transformation/file/index.js:122:22)
at Pipeline.transform (/data/projects/ng2-app/node_modules/babel-core/lib/transformation/pipeline.js:42:16)
npm ERR! Linux 3.13.0-71-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "build:app"
npm ERR! node v5.3.0
npm ERR! npm v3.5.3
npm ERR! code ELIFECYCLE
问题
- 我不关心使用
装饰
语法,所以我我可以重写这个使用ES6 / ES2015呢? - I don't care about using the
decorator
syntax, so I can I rewrite this to use ES6/ES2015 instead?
Question
推荐答案
这是因为你使用的是巴贝尔6和装饰,目前它被禁用,但是你可以把它与传统的插件工作变换-decorators遗留
。其理由去功能是语法将在不久的将来改变。 https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy
It is because you are using Babel 6 and decorators are currently disabled for it, but you can make it work with the legacy plugin transform-decorators-legacy
. The reason for disableing is that the syntax will change in the near future. https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy
这篇关于我如何写不修饰语法angular2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文