Reputation: 2523
I want to create a theme package with css, js and images. The theme package looks like:
packages/
theme
css
theme.css
js
theme.js
img
logo.png
I can package css and js like so:
Package.onUse(function(api) {
var themeFiles = [
'theme/css/theme.css',
'theme/js/theme.js'
];
api.addFiles(themeFiles, 'client');
});
Do I need to package the images to use them? I tried to ref the logo png like this but it didn't work:
<a href="/packages/theme/img/logo.png">logo</a>
How can non css or js files can be distributed and used as meteor packages?
Thanks
Upvotes: 1
Views: 236
Reputation: 7875
You could also use api.addAssets(filenames, architecture)
and access from client like /packages/username_package-name/file-name
see https://docs.meteor.com/api/packagejs.html#PackageAPI-addAssets
Upvotes: 0
Reputation: 22696
You need to declare package assets such as images using the regular api.addFiles
method :
api.addFiles("img/logo.png","client",{
isAsset: true
});
isAsset
is not mandatory here because we're adding an image, but note that if we wanted to add JS or CSS files as public staticly served files, we would have to specify this option to avoid Meteor bundling these files along with the concatenated/minified initial app JS/CSS.
Then you will be able to reference these assets using this type of path :
`/packages/package-author_package-name/img/logo.png`
Given that your package name is package-author:package-name
.
Upvotes: 3