Skip to content

Instantly share code, notes, and snippets.

@janmisek
Created November 30, 2016 07:30
Show Gist options
  • Save janmisek/4920e0483aa7bb647ff61588be9816b1 to your computer and use it in GitHub Desktop.
Save janmisek/4920e0483aa7bb647ff61588be9816b1 to your computer and use it in GitHub Desktop.
Solution to use pods based components in in-repo addon (working on ember 2.8 and 2.9 probably since 2.5)
/**
There is no support for pod based components in addons as of ember 2.9. Also as ember is moving to https://github.com/emberjs/rfcs/blob/master/text/0143-module-unification.md
pods are being discontinued (no longer supported). But for better organization of large in-repo addons pods are a must.
This gist provides solution how to use pods based components in in-repo addon. Even components.js based in pods of addon works problem is that template is not
being compiled. Following adjustments provides also compilation of template. Its only solution I found because of private
anonymous function in ember-cli which handles template compilation of addons.
To use pods in addon
Addon has to have enabled pod
addon-name/.embercli => "usePods": true
Addon and app has to have same podModulePrefix
addon/config/environment.js + app/config/environment.js => podModulePrefix: '<app or addon name>/pods',
Include following in application ember-cli-build.js
**/
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var util = require('util');
var path = require('path');
var mergeTrees = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
var CustomApp = function () {
return CustomApp.super_.apply(this, arguments);
};
util.inherits(CustomApp, EmberApp);
CustomApp.prototype._templatesTree = function () {
var trees = [EmberApp.prototype._templatesTree.apply(this, arguments)];
if (this.options.podSupportForAddons) {
this.options.podSupportForAddons.forEach(function (c) {
var podTemplates = new Funnel(
path.join('node_modules', c.name, 'app'),
{
exclude: ['templates/**/*'],
include: this._podTemplatePatterns(),
destDir: this.name + '/',
annotation: 'Funnel: Addon pod Templates'
});
trees.push(podTemplates);
}.bind(this));
}
return this._cachedTemplateTree = mergeTrees(trees, {overwrite: true});
};
module.exports = function (defaults) {
var app = new CustomApp(defaults, {
podSupportForAddons: [
{name: 'my-addon-name', pods: 'pods'} // pods = pods prefix
]
});
// Use `app.import` to add additional libraries to the generated
// output files.
//
// If you need to use different assets in different
// environments, specify an object as the first parameter. That
// object's keys should be the environment name and the values
// should be the asset to use in that environment.
//
// If the library that you are including contains AMD or ES6
// modules that you would like to import into your application
// please specify an object with the list of modules as keys
// along with the exports of each module as its value.
return app.toTree();
};
@murli2308
Copy link

murli2308 commented Dec 27, 2016

I am writing an in-repo-engine. how to use pods with in-repo-engine ?

I tried your solution but it is not working. I replaced node_modules with lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment