Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The curious case of /public/assets/ in a Meteor project

In my Meteor 1.10.2 project, I have created a folder called assets inside the /public/ folder. When the Meteor application is built, I find this assets folder has been copied to these locations, as a direct child of the web.browser... folders:

/.meteor/local/build/programs/web.browser/assets/
/.meteor/local/build/programs/web.browser.legacy/assets

However, if I rename the folder to Assets (or if I give it any other name), when the application is built, I find it deeper in, inside the app folder at:

/.meteor/local/build/programs/web.browser/app/Assets/
/.meteor/local/build/programs/web.browser.legacy/app/Assets/

What is the logic behind this? What is the intention? What are the best practices for working with a folder at /public/assets/? Are there any other words that are given special treatment when used as names for folders inside the /public/ folder?

like image 299
James Newton Avatar asked Jul 15 '20 08:07

James Newton


1 Answers

FWIW, this behaviour is specifically due to meteor tools bundler:

https://github.com/meteor/meteor/blob/release/METEOR%401.10.2/tools/isobuild/bundler.js#L719-L725

  setTargetPathFromRelPath(relPath) {
    // XXX hack
    if (relPath.match(/^(packages|assets|dynamic)\//)) {
      this.targetPath = relPath;
    } else {
      this.targetPath = files.pathJoin('app', relPath);
    }

Therefore we can see that there are 3 special directory names that exhibit this special behaviour:

  • packages
  • assets
  • dynamic

Example with public assets:

public assets

These assets bundled in build:

assets copied in build

For "packages", while we can understand that this is how Meteor ships the static assets of packages (i.e. when they call api.addAssets(), we can also see that there is a potential for collision, in the (however unlikely) case we use a pathname like "public/packages/my-package-name".

As for "assets", the initial name was "static", but I do not think it was publicly documented either.

And for "dynamic", I do not know yet what is its exact purpose, but we can see that it serves its content as "javascript" type (at least SVG files), whereas the first 2 serve them as "text/plain".

SVG file in dynamic served as javascript

like image 70
ghybs Avatar answered Sep 21 '22 15:09

ghybs