You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I am currently porting an ember 1.12 app (with grunt as build tool) to ember 1.13.13 ( with ember-cli 2.12.0). I've done most of the files restructure (ES6 modules and stuff). Now the issue I have is that the app has two "app" folders. Difference being that the second one has only the components and routes that should be available just if I go via a different index.html file.
Project Structure:
My solution for this was to have 2 EmberApps in ember-cli-build.js and then chain the trees (and then include the generated "client.js" asset from the first app into the index of the second one).
But I found out I cannot tell EmberApp what folder to look into for the app files.
Or that if ember itself should be included in the resulted "client.js".
I looked into ember-cli/lib/broccoli/ember-app.js and made changes to fit my needs.
function "appOptions" just gives back babel options
var app = new EmberApp(defaults, appOptions());
var appAdmin = new EmberApp(defaults, appOptions({
baseAppDir: 'app-admin',
appOnlyJS: true,
outputPaths: {
app: {
js: '/assets/client.admin.js',
html: 'index.admin.html',
css: {
'app': `/assets/client.admin.css`,
}
},
vendor: {
js: '/assets/vendor.admin.js'
}
}
}));
let dependencies = [
...,
];
dependencies.forEach(dependency => {
app.import(dependency);
appAdmin.import(dependency);
});
return app.toTree(appAdmin.toTree());
Notice the baseAppDir and appOnlyJS options.
I can create a pull request if this is the way .. but maybe there's a more elegant solution?
After reading up the ember-app class more .. refactored to only one option additionalAppFolders: ['app-admin'] .. instead of the baseAppDir and appOnlyJS. Now I just merge the passed 'app-admin' folder with appTree. Simpler solution but maybe have something similar to outputPaths called inputPaths` so you can pass the project folders as such:
@akondo06 are these truly separate apps or could they be merged into one app folder instead? You could use an in-repo-addon or engine to separate them, but unsure if that will work with Ember 1.13.
@rwwagner90 they have to be separated. Reason being that the second one has extra components, services and models that can be viewed only by administrators (accessed by index.admin.html instead of index.html).
It adds up a bit of security there.
I already looked at engines but it will take a bit more time to refactor than what I have.
I will not stop at v1.13.13 but because things get cleaned up in v2.0.0, I have to ged rid of all deprecations before that. After v2, things will go smooth.
Back to my problem.
After better understanding EmberApp, I figured that I can just merge the second folder into the app tree before calling app.toTree().
const mergeTrees = require('ember-cli/lib/broccoli/merge-trees');
const WatchedDir = require('broccoli-source').WatchedDir;
.....
let app = new EmberApp(...);
let appAdmin = new EmberApp(....);
let additionalAppFolders = ['app-admin'];
if(additionalAppFolders.length) {
let additionalAppTrees = additionalAppFolders.map(folder => {
return new WatchedDir(appAdmin._resolveLocal(folder));
});
appAdmin.trees.app = mergeTrees([appAdmin.trees.app].concat(additionalAppTrees), {
overwrite: true,
annotation: 'TreeMerger (app with additional app folders)'
});
}
....
return app.toTree(appAdmin.toTree());
Only downside that I can see now is the vendor.js file (which is the same for both) being built twice.
I agree that it is slightly sub-optimal to duplicate the final vendor.js output file, but it doesn't seem like it should be terribly inefficient (we already dedupe addon's treeFor hooks when versions match and whatnot).
I think the above is a decent solution to the problem, so I'm going to close this. I'm happy to continue the discussion though...
Activity
akondo06 commentedon Mar 22, 2017
After reading up the ember-app class more .. refactored to only one option
additionalAppFolders: ['app-admin'].. instead of thebaseAppDirandappOnlyJS. Now I just merge the passed 'app-admin' folder withappTree. Simpler solution but maybe have something similar tooutputPathscalled inputPaths` so you can pass the project folders as such:RobbieTheWagner commentedon Mar 22, 2017
@akondo06 are these truly separate apps or could they be merged into one app folder instead? You could use an in-repo-addon or engine to separate them, but unsure if that will work with Ember 1.13.
akondo06 commentedon Mar 22, 2017
@rwwagner90 they have to be separated. Reason being that the second one has extra components, services and models that can be viewed only by administrators (accessed by
index.admin.htmlinstead ofindex.html).It adds up a bit of security there.
I already looked at engines but it will take a bit more time to refactor than what I have.
I will not stop at
v1.13.13but because things get cleaned up inv2.0.0, I have to ged rid of all deprecations before that. After v2, things will go smooth.Back to my problem.
After better understanding
EmberApp, I figured that I can just merge the second folder into theapp treebefore callingapp.toTree().Only downside that I can see now is the
vendor.jsfile (which is the same for both) being built twice.rwjblue commentedon Mar 23, 2017
That looks pretty close to what I would think also, but don't merge them at the end like that.
Slight modification:
rwjblue commentedon Mar 23, 2017
I agree that it is slightly sub-optimal to duplicate the final
vendor.jsoutput file, but it doesn't seem like it should be terribly inefficient (we already dedupe addon'streeForhooks when versions match and whatnot).I think the above is a decent solution to the problem, so I'm going to close this. I'm happy to continue the discussion though...
akondo06 commentedon Mar 23, 2017
Thanks @rwjblue will give that a shot.