With the nathantreid:static-assets build plugin you can now import static assets in your JS files, eg:
import myImage from '/imports/client/my-image.png';` console.log(myImage); // http://localhost:3000/static/imports/client/my-image.png
There are many times you may want to import a static asset into Meteor, but have been unable to. Perhaps an NPM package you wanted to use imported an image, and you had to jump through hoops to get it working? No longer! This newly released build plugin is here to save the day!
I’ve been meaning to get around to this for a while and a post I saw on the forums today finally motivated me to do it.
By default the plugin will process
svg files and will host them at
static/path/to/your/file. The extensions and hosting prefix (
static/) can be configured via
package.json. See the Atmosphere or GitHub page for more info.
A sample project demoing importing an image (test.png) can be found here: https://github.com/nathantreid/meteor-static-assets-sample
While I started with just
svg files, I think it makes sense to default to the most common, so please let me know what file extensions you think should be handled by default!