使用MobX可观察的装饰器和create-react-app [英] Using MobX observable decorators with create-react-app
问题描述
MobX文档告诉我,我必须使用转换插件transform-decorators-legacy并确保它在插件列表中排在首位",以使装饰器正常工作. MobX样板项目建议我需要一个.babelrc
:
The MobX docs tell me I must "use the transform plugin transform-decorators-legacy and make sure it is first in the plugins list", in order for the decorators to work. The MobX boilerplate project suggests I need a .babelrc
like:
{
"presets": [
"react",
"es2015",
"stage-1"
],
"plugins": ["transform-decorators-legacy", "react-hot-loader/babel"]
}
如何使用create-react-app生成的项目来做到这一点?任何尝试使用@
装饰器的错误.即使在弹出"项目后也没有.babelrc
.
How do I do that with a create-react-app generated project? Any attempt to use @
decorators errors. There is no .babelrc
even after the project is 'ejected'.
推荐答案
You can not use decorator syntax unless you eject
. However, you can use MobX without @
since it is just a syntax sugar.
Dan Abramov 已阐明了此原因
Dan Abramov has articulated the reason for this
我们的立场很简单:我们添加稳定的变换 足够(如异步/等待)或被Facebook大量使用(如课堂) 特性).只有这样,我们才能自信地提出建议, 因为如果标准有所变化,我们将编写并发布 一个codemod以便从他们那里迁移过来.
Our position is simple: we add transforms that are either stable enough (like async/await) or heavily used by Facebook (like class properties). Only that lets us be confident in suggesting them, because if something changes in the standard, we’ll write and release a codemod to migrate away from them.
由于我们当前不使用装饰器,因此我们不打算使用它 如果标准成为标准,我们自己可以提供迁移路径 不相容.此外,甚至还没有正式支持装饰器 Babel撰写(遗留遗产是有原因的).当它们被配置时 人们会稍微错误地责怪React.
Since we don’t currently use decorators, we don’t take it upon ourselves to provide a migration path if the standard becomes incompatible. Additionally decorators aren’t even officially supported by Babel (-legacy is there for a reason). And when they are configured slightly incorrectly people blame React.
您可能还想研究 create-react-app-mobx
You also might want to look into create-react-app-mobx
相关讨论:
- https://github.com/facebookincubator/create-react-app/issues/214
- https://github.com/mobxjs/mobx/issues/521
- https://github.com/facebookincubator/create-react-app/issues/411
- https://github.com/facebookincubator/create-react-app/issues/214
- https://github.com/mobxjs/mobx/issues/521
- https://github.com/facebookincubator/create-react-app/issues/411
这篇关于使用MobX可观察的装饰器和create-react-app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!