ember-cli addon bower dependency

2019-08-30 11:27发布

问题:

Ember-CLI 1.13.8

I'm having trouble loading an addon i've just created into a separate test app. (This is my first addon.)

Because i'm developing locally i used npm link like so:

    $ cd ember-cli-foo
    $ npm link
    $ cd ../test-app
    $ npm link ember-cli-foo

And npm has created the link under node_modules.

The addon also has a bower dependency. I read somewhere that the main index.js inside the addon dir should look like:

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

    module.exports = {
      name: 'ember-cli-foo',

      included: function(app) {
        this._super.included(app);
        app.import(app.bowerDirectory + "/foo/web/foo.js");
      }
    };

And a blueprint:

    module.exports = {
      description: ""

      afterInstall: function(options) {
        return addBowerPackageToProject("foo");
      }
    };

But when i try running ember serve ...

    Path or pattern "bower_components/foo/web/foo.js" did not match any files

Realising that i likely needed to point to the addon's bower_components, i tried prepending to the import path:

    app.import("node_modules/ember-cli-foo/" + app.bowerDirectory + "/foo/web/foo.js");

But that just got me:

    Path or pattern "node_modules/ember-cli-foo/bower_components/foo/web/foo.js" did not match any files

That path is correct, though. I then tried:

    $ ember install ember-cli-foo

... which produces:

    Registry returned 404 for GET on https://registry.npmjs.org/ember-cli-foo

Can anyone tell me what i'm missing? How can i install the addon into a test app using the local npm link?

UPDATE

Perhaps i'ma bit closer. I found this tip t get ember to run the bluprint:

$ ember g ember-cli-foo

And indeed ember replied, "installing ember-cli-foo". However,when i run ember serve i get the same error about not finding the dependency, no matter the path i feed it. The page where i found the above tip suggests the same as what i'd started with.

Doing ember install ember-cli-foo still results in a complaint that the package can't be found on npm's server.

UPDATE II

I deleted the app and started over:

$ ember new test
$ cd test
$ npm link ember-cli-foo
$ ember g ember-cli-foo
$ ember serve
...
ENOENT, no such file or directory '/home/bally/dev/apps/test/tmp/concat_with_maps-input_base_path-RopBTsxP.tmp/0/bower_components/foo/web/foo.js'

Indeed, tmp is empty.

$ ember install ember-cli-foo

Same complaint--trying to fetch it remotely.

回答1:

When doing addon development locally you have to manually create the entry in the conusming app's bower.json referencing foo.js. Unfortunately you can't do ember install ember-cli-foo until after the addon exists on either github or npm.