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...
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...
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,
});
},
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With