Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing from an addon #20

Open
lolmaus opened this issue Oct 27, 2015 · 6 comments
Open

Importing from an addon #20

lolmaus opened this issue Oct 27, 2015 · 6 comments

Comments

@lolmaus
Copy link

lolmaus commented Oct 27, 2015

ember-inline-svg fails importing an svg from an addon's public/ folder.

I would like to inline an svg from an addon's public/ folder both in the main app and in the addon itself.

@lolmaus
Copy link
Author

lolmaus commented Oct 27, 2015

@vitch
Copy link
Contributor

vitch commented Nov 23, 2015

We are using the following workaround in an internal addon we have developed which relies on ember-inline-svg:


addonPath: function(path) {
    if (!this.isDevelopingAddon()) {
      path = ['node_modules', this.name, path].join('/');
    }
    return path;
  },

included: function(app) {
  var emberInlineSvgOptions = app.options.svg || {};
  if (!emberInlineSvgOptions.paths) {
    emberInlineSvgOptions.paths = ['public']; // TODO: use ember-inline-svg's defaults directly: https://github.com/minutebase/ember-inline-svg/pull/19
  }
  var ourPublicPath = this.addonPath('public');
  if (emberInlineSvgOptions.paths.indexOf(ourPublicPath) === -1) {
    emberInlineSvgOptions.paths.push(ourPublicPath);
  }
  app.options.svg = emberInlineSvgOptions;

  this._super.included(app);

  this.addons.forEach(function(addon){
    if (['ember-inline-svg'].indexOf(addon.name) > -1) {
      addon.included.apply(addon, [app]);
    }
  });

},

in addition to having ember-inline-svg in dependencies rather than devDependencies for our addon this seems to work well...

@lolmaus
Copy link
Author

lolmaus commented Nov 23, 2015

@vitch Thank you so much for sharing! Where does this code go?

@vitch
Copy link
Contributor

vitch commented Nov 23, 2015

In the index.js of the addon which depends on ember-inline-svg

@lolmaus
Copy link
Author

lolmaus commented Nov 26, 2015

@vitch I've tried your workaround and it worked for me. Thank you so much!

The only issue is that and addon's SVGs located at my-addon/public/svg/foo.svg is accessed via:

{{inline-svg 'svg/foo'}}

According to Ember CLI docs, addon's public folder gets mixed into the app's public folder as a subfolder. For example, when you access the same SVG file via <img> or CSS, you would do:

.foo {
  background-image: url('/my-addon/svg/foo.svg');
}
<img src='/my-addon/svg/foo.svg'>

For consistency, I would like ember-inline-svg to access files like this:

{{inline-svg 'my-addon/svg/foo'}}

Can your code be adjusted to achieve that?

@quantuminformation
Copy link

Have you guys worked out how to import from node modules in a brocfile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants