@ember-decorators/babel-transforms

中文文档
5.2.0发布于 2019/04/07MIT近 30 天下载 1.5万

Configures the consuming ember-cli app's or addon's Babel transpiler for decorators.

原始使用文档

@ember-decorators/babel-transforms

Build Status npm version Greenkeeper badge dependencies Status devDependencies Status

Enables your app or addon to use decorators for ES6 classes.

Installation

For apps

# latest version
ember install "@ember-decorators/babel-transforms"

# latest 2.x version
ember install "@ember-decorators/babel-transforms@^2"

For addons

Tests and dummy app only

If you're developing an addon and only intend to use decorators in your tests and / or dummy app (tests/dummy), just install this addon as a regular devDependency:

ember install @ember-decorators/babel-transforms

You can now use decorators in your tests/* directories, but not in your addon directory.

Internal use only

If you're developing an addon that only uses decorators interally, e.g. you don't export any decorators that the user is supposed to use, then it's sufficient to install this addon with the -S flag, so it is added as a dependency as opposed to the default devDependency

ember install -S @ember-decorators/babel-transforms

In addition to tests/*, you can now use decorators in your addon directory. However, do not make them public API, i.e. do not expect the user of you addon to be able to use these decorators.

Exporting decorators for the user

If you want to not only employ decorators internally, but also make them public API, so that users of your addon can use your decorators, then the consuming app or addon has to be properly configured for decorator usage.

This means, that users of your addon are required to add @ember-decorators/babel-transforms to their project as well. You can either instruct them to do so in your installation instructions and link them here or automatically add the dependency in the default blueprint using addAddonToProject:

// blueprints/<your-addon-name>/index.js
module.exports = {
  normalizeEntityName() {}, // no-op since we're just adding dependencies

  afterInstall() {
    return this.addAddonToProject('@ember-decorators/babel-transforms'); // is a promise
  }
};

You can also add it as a dependency (as opposed to the default devDependency):

// blueprints/<your-addon-name>/index.js
module.exports = {
  normalizeEntityName() {}, // no-op since we're just adding dependencies

  afterInstall() {
    return this.addAddonToProject({
      name: '@ember-decorators/babel-transforms',
      blueprintOptions: { save: true }
    }); // is a promise
  }
};

Also, don't forget to add @ember-decorators/babel-transforms to your own addon in the first place. :wink:

ember install -S @ember-decorators/babel-transforms

Configuration

You can configure this addon in you ember-cli-build.js file:

/* eslint-env node */
'use strict';

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
  const app = new EmberAddon(defaults, {
    '@ember-decorators/babel-transforms': {
      disable: false
    }
  });

  return app.toTree();
};

The only option is disable, which defaults to false. If you set disable to true, Babel will not get configured for decorators.

版本与发布记录

@ember-decorators/babel-transforms 共发布 26 个版本,首次发布于 2017/11/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.2.0latest2019/04/077 年前
5.1.42019/03/037 年前
5.1.32019/02/127 年前
5.1.22019/01/247 年前
5.1.12019/01/187 年前
5.1.02019/01/187 年前

关于 @ember-decorators/babel-transforms 的常见问题

@ember-decorators/babel-transforms 是什么?

Configures the consuming ember-cli app's or addon's Babel transpiler for decorators.

如何安装 @ember-decorators/babel-transforms?

在项目目录运行 npm install @ember-decorators/babel-transforms,或使用 pnpm add / yarn add / bun add。

@ember-decorators/babel-transforms 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/ember-decorators__babel-transforms 是否存在。

@ember-decorators/babel-transforms 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js 6.* || 8.* || >= 10.*。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ember-decorators/babel-transforms 可以商用吗?

@ember-decorators/babel-transforms 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ember-decorators/babel-transforms 的下载量有多少?

根据 npm 官方下载统计,@ember-decorators/babel-transforms 在 2026/10/14 – 2026/11/12 这 30 天内被下载 15,465 次,日均约 516 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ember-decorators/babel-transforms 还在维护吗?

最新版本 5.2.0 发布于 2019/04/07(7 年前);至今共发布 26 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/11/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。