1

您需要如何在 Ember 插件中工作,以在安装插件时包含 bower 包。

1)我安装了我想包含在我的插件中的凉亭包bower instal packagename --save

2)然后在我的插件中,在根目录中,编辑index.js,看起来像这样:

/* jshint node: true */
'use strict';

module.exports = {
  name: 'my-ember-component',
  included: function(app) {
    this._super.included(app);

    if(app.import){
      app.import(app.bowerDirectory + '/path-to-package/package.js');
    }
  }
};

但是,当我尝试启动安装了插件的应用程序时,我得到一个 ENOENT: no such file or directory, stat '/my-ember-application/tmp/source_map_concat-input_base_path-bWTPoVC9.tmp/0/bower_components/path-to-package/package.js

我想避免必须手动将 bower 依赖项添加到我安装插件的每个应用程序中。

注意:我npm link用来调试我的插件,也许这可能是问题的根源?

4

1 回答 1

2

通常,插件的凉亭组件会在ember install addon.

但是由于您正在进行本地开发并使用 npm 链接。你需要模拟这个。你可以这样做:

ember generate your-addon-name

解释。

在 ember cli 文档中查看有关默认蓝图的文档。

安装后会自动运行与插件同名的蓝图(除非明确更改,见上文)(在开发中,必须在链接后手动运行)。在这里,您可以将插件的 bower 依赖项绑定到客户端应用程序中,以便实际安装它们。

简而言之,您需要为您的应用程序创建一个默认蓝图并在其中添加 bower 依赖项。

创建你的文件:

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

  afterInstall: function() {
    return this.addBowerPackageToProject('BOWER PACKAGE NAME'); // is a promise
  }
};

然后当你运行默认蓝图时

ember generate your-addon-name
于 2016-03-01T16:02:39.663 回答