Search code examples
meteordirectory-structure

Public static assets in module folders?


I want to organize my Meteor app in modules, i.e. having a folder for each specific section or functionality of my app containing all related files.

This would preferably also include static assets such as images but the special public/ folder only seems to work in the project root.

Or am I missing something?

For my project, it feels like overkill (less clean, even) having the overhead of creating a proper package for every little module of my app.


Solution

  • Unfortunately the only way to do it is to use a package. You can add static assets to a package, and the file can be accessed with the URL: /packages/[package name]/[path to file]. Here's an example of a package.js for hopscotch:

    Package.describe({
      summary: 'A framework to make it easy for developers to add product tours.'
    });
    
    Package.onUse(function(api) {
      api.versionsFrom('1.0.0');
      api.addFiles('img/sprite-green.png', 'client');
      api.addFiles('img/sprite-orange.png', 'client');
      api.addFiles('css/hopscotch.css', 'client');
      api.addFiles('js/hopscotch.js', 'client');
    });
    

    As you can see, all of the images are under the img directory within the package. To access the sprite-green.png file, I would use /packages/hopscotch/img/sprite-green.png.