aurelia / bundler

A library for bundling JavaScript, HTML and CSS for use with SystemJS.
MIT License
37 stars 25 forks source link

Is image loader available? #73

Closed oswaldofreitas closed 8 years ago

oswaldofreitas commented 8 years ago

Can I create an image bundle like this?

"dist/home-images": {
      "includes": [
        "images/**/*!image"
      ],
      "options": {
          "inject": true
      }
    }
ahmedshuhel commented 8 years ago

There is a image plugin for systemjs here https://github.com/systemjs/plugin-image You can try it in your app and bundler should work. Your configuration looks OK to me. Before using that though you have to install the plugin like: jspm install image.

On a side note, It seems a bit odd to try load and use all the images with systemjs (images/*/). IMHO, specific images may make sense to be used like this in some scenario.

bhaeussermann commented 8 years ago

This does not work for me. The image paths are added to config.js, and the bundle file is created, but the contents of the images are not added to the bundle file.
Instead of loading the bundle file, the browser still loads each image separately.
(disclosure: all images are svg files).

Here is the contents of the bundle file:

System.registerDynamic("github:systemjs/plugin-image@0.1.0/image.js", [], true, function($__require, exports, module) {
  ;
  var define,
      global = this,
      GLOBAL = this;
  exports.build = false;
  exports.fetch = function(load) {
    return new Promise(function(resolve, reject) {
      var img = load.metadata.img = new Image();
      img.onerror = reject;
      img.onload = function(evt) {
        try {
          delete img.onload;
        } catch (err) {
          img.onload = function() {};
        }
        resolve('');
      };
      img.src = load.address;
    });
  };
  exports.instantiate = function(load) {
    return load.metadata.img;
  };
  return module.exports;
});

System.registerDynamic("github:systemjs/plugin-image@0.1.0.js", ["github:systemjs/plugin-image@0.1.0/image"], true, function($__require, exports, module) {
  ;
  var define,
      global = this,
      GLOBAL = this;
  module.exports = $__require('github:systemjs/plugin-image@0.1.0/image');
  return module.exports;
});
gheoan commented 8 years ago

plugin-image does not support bundling, only loading.