1

I want to create a library containing general-purpose javascript functions and classes for use in any Ember object in an Ember-cli project. What's the recommended procedure for doing this?

3
  • You would put them in your /utils directory Commented Dec 8, 2015 at 16:08
  • 1
    Is this for you own project, or for sharing? Commented Dec 8, 2015 at 16:36
  • This is for my own project. Commented Dec 8, 2015 at 22:51

2 Answers 2

2

You should generate new util in Ember CLI:

ember g util your-name

Then you can import it using:

import yourName from '../utils/your-name'
Sign up to request clarification or add additional context in comments.

1 Comment

Is the from '../utils/your-name' relative to location of the comsumming object? I tried what you suggested before posting this question. I kept getting a "could not find module error." I posted another question regarding this. Please search 34167418. Do you know what's causing the error?
0

Creating an addon is the Ember-CLI-preferred method of doing that. Addons can be published to NPM and installed in Ember CLI projects using NPM. This makes it incredibly easy to share code. There's a guide for developing addons on the Ember CLI site.

3 Comments

But this is just a simple utility function that's of no value to anyone else, so publishing to NPM seems a bit inappropriate.
I may have misread your question. I thought you wanted a way to share between different Ember CLI projects. If you want a function for just one project, then a utility is the way to go.
I can't get import to work no matter what I tried. Please see post 34167418.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.