When you’re in the process of developing a package, it can be useful to be able to import it into another project locally without having to publish it first. By doing this, you can test it within the context of a larger project instead of relying entirely on unit tests.
This guide will show you how to take an Elixir package you’ve made locally and import it into another project using the file path.
Name the dependency
Open the mix.exs
file. Look for the project definition, which should look like this:
def project do
[
app: :my_dependency,
version: "0.1.0",
...
]
end
Make sure to update the name of the app
property to whatever you would like to import this package as in other projects.
Get the file path
Copy the complete file path to the root of your package.
Import the package
In the project you’d like to import the package, open your mix.exs
file.
Find deps
and add your package to the array using the path
property:
defp deps do
[
{:word_list, path: "/path/to/your_dependency"}
]
end
Test with iex
Now you can test whether your project has access to the dependency. Run an iex
shell for your project.
iex -S mix
Then, check that you have the ability to run functions from your dependency.
iex> MyDependency.hello
:world
More content
- I published my first Elixir package to hex!
- What's the best questions you've been asked in a job interview?
- What was the first program you wrote?
- The weird quirk of JavaScript arrays (that you should never use)
- Does Elixir have for loops?
- Learn Elixir with me!
- Project Tours: Bread Ratio Calculator
- Changing Emoji Skin Tones Programmatically
- I made my first svg animation!
- 5 tips for publishing your first npm package
- 4 Hugo Beginner Mistakes
Top comments (0)