How do I reuse my own modules in distinct projects of mine?

Hello,

Say I’ve built a module that helps with drawing a schedule widget.
Now I’d like to use that module in one of my apps. Perhaps later I’d like to use my schedule widget in multiple projects.
How do I do that? Is there a better way than copy pasting the same files in every project ?

I guess I could upload my project to elm-lang.org but, as of today, I’m not really proud of my Elm skills enough to publish Elm code on the internet for everyone to see.
Also, the case might arise that your module has to stay closed source because your customer is paying for the code and he wants the code to stay closed source.

So, how could I reuse one of my private module in different projects ?

Thanks for your help.

1 Like

Not sure if it’s what you’re looking for, but you might wanna take a look at this

1 Like

Nice, I’m going to have a look and see if it’s possible to add a local repository (a repo that would live only on my local computer) as a dependency. I’ll probably end up creating a private remote repo anyway, but a local directory would be simpler for a start.

In that case, there’s also an option to add another source directory in elm.json

:open_file_folder:Projects
:open_file_folder:MyProject1
┃ ┗ :scroll:elm.json
:open_file_folder:MyProject2
┃ ┗ :scroll:elm.json
:open_file_folder:Libs
┃ ┗ :package:ScheduleWidget

elm.json:

"source-directories": [
    "./src/Elm",
    "../Libs/ScheduleWidget"
]

But a remote repo is always preferable

3 Likes

this works well with a monorepo setup

This approach also works with with git submodules. I’ve used this a few times and it worked really well.

3 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.