Place to put assets for dev/test in emberjs

霸气de小男生 提交于 2019-12-24 08:25:42

问题


I'm using mirage to mock some data and I'd like to mock an <img> with the appropriate file.

The problem is that I will have to place the image in /public/assets and the images placed there will be deployed later on as well.

Is there a way to avoid this? I couldn't find a recommendation in the ember cli website (https://ember-cli.com/user-guide/#asset-compilation)

I found one addon that could do this (ember-test-assets), but I'd like to avoid installing extra addons as much as possible.

Thanks!


回答1:


You can exclude files in ember-cli-build.js with some help of Broccoli

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const Funnel = require('broccoli-funnel');

module.exports = function(defaults) {
  let app = new EmberApp(defaults, {
    // Add options here
  });

  // Filter your test files in 'production'
  if (EmberApp.env() === 'production') {
    return new Funnel(app.toTree(), {
      exclude: ['**/test-*'] // e.g. any file prefixxed with 'test-'
    });
  }
  return app.toTree();
};

References:

  • EmberApp.env(): https://github.com/ember-cli/ember-cli/blob/d97d96aa016fbe8108c2d2744c9823a0ea086b94/lib/broccoli/ember-app.js#L469
  • broccoli-funnel: https://github.com/broccolijs/broccoli-funnel (see exclude)


来源:https://stackoverflow.com/questions/51958155/place-to-put-assets-for-dev-test-in-emberjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!