Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import custom library in ember-cli

I have web app and Ember app in iframe. I want to import custom library from web app to ember app like global variable. Library look like object with function:

var helpers = {
    helper1: function() {},
    helper2: function() {}
};

Library working with sockets and will the same for both applications.

I wrote:

app.import("./../../../public/scripts/js-helpers.js"); //file located in web app 

I can't access variable helpers in project and ember-cli copy folder public into their working folder. Sorry if question is stupid, I can't understand ember-cli import principles.

like image 337
user1156168 Avatar asked Mar 19 '23 15:03

user1156168


1 Answers

I'll propose one solution, which I find to be the easiest. You won't have globally scoped variables, but you use then ES6 module approach.

For example purposes, let's say you have a file under app_name/lib/ called helper.js. lib is a directory you create for holding your custom libraries. You don't have to use that name. Use the export default command as such:

export default {
    helper1: function() {},
    helper2: function() {}
};

Then, lets say you need this in a route. Here could be one such route:

import helper from 'app_name/lib/helper';

export default Ember.Route.extend({
   model: function(){
      helper.helper1();
}

helper is the name of what you imported, and represents the object that you exported in your helper.js. This method seems to be the style in which Ember-CLI suggests you should use

like image 158
mistahenry Avatar answered Mar 29 '23 20:03

mistahenry