Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing a public tree in an ember-cli addon

Tags:

ember-cli

I am completely puzzled when I read all the information I can gather about sharing a public assets directory from an ember-cli addon.

Is there anybody having it working around here? Any ref to an example addon doing it would also be appreciated...

like image 718
Mike Aski Avatar asked Dec 09 '14 11:12

Mike Aski


2 Answers

So... I finally found a way to share the static assets: - I placed the files in vendor/assets directory - Declared the files to shared (each file...) into the addon's index.js file @ addon's root

app.import('vendor/assets/my_image.png');

An interesting option of app.import statement I found in my searches is destDir, which allows to customize the target publication path of the asset:

app.import('vendor/assets/a/b/c/my_image.png', { destDir: 'x/y' });

will publish my_image.png @ URL /assets/x/y/my_image.png

Hoping this will help others to save time...

like image 139
Mike Aski Avatar answered Nov 08 '22 22:11

Mike Aski


Assets of addons are available under a namespace. For example if there is a file in public/assets/image.png in your addon, this file is available under /my-addon/assets/image.png.

If you don't want to use a namespace, you can overwrite the treeForPublic hook in the addon definition as demonstrated in this gist:

const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');

module.exports = {
  name: require('./package').name,

  treeForPublic: function(tree) {
    const assetsTree = new Funnel('public');
    return mergeTrees([tree, assetsTree], {
      overwrite: true,
    });
  },
};
like image 39
tsauerwein Avatar answered Nov 08 '22 23:11

tsauerwein