[英]Sharing a public tree in an ember-cli addon
I am completely puzzled when I read all the information I can gather about sharing a public
assets directory from an ember-cli
addon. 当我阅读有关从
ember-cli
插件共享public
资源目录的所有信息时,我感到非常困惑。
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 所以...我终于找到了一种共享静态资产的方法: - 我将文件放在
vendor/assets
目录中 - 声明要共享的文件(每个文件......)到addon的index.js
文件中@adon的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
语句的一个有趣选项是destDir
,它允许自定义资产的目标发布路径:
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
将发布
my_image.png
/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
. 例如,如果您的插件中有
public/assets/image.png
文件,则此文件位于/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 : 如果你不希望使用一个命名空间,可以覆盖
treeForPublic
作为证明这个插件定义挂钩要点 :
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,
});
},
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.