I have an Elm package (source + all build artifacts) in a local directory, and I would like to use it from another Elm package, without publishing the library. So my directory setup looks like this:
/
my-lib/
elm-package.json
my-app/
elm-package.json
First of all, running elm-package install in the library package's directory doesn't seem to do anything more than just building the package; it doesn't get installed in any global directory as far as I can tell.
I've added my-lib to my-app/elm-package.json as such:
"dependencies": {
"elm-lang/core": "1.0.0 <= v < 2.0.0",
"my-vendor/my-lib": "0.0.1 <= v <= 0.0.1"
}
So when I run elm-make in the dependent package's directory, it complains
There are no versions of package
my-vendor/my-libon your computer.
elm-package install complains about the same thing.
The only workaround I've found is to create the following symlinks in my-app:
/
my-app/
elm-stuff/
packages/
my-vendor/
my-lib/
0.0.1@ -> /my-lib/
build-artifacts/
my-vendor@ -> /my-lib/build-artifacts/my-vendor
I also had to add the following to /my-app/elm-stuff/exact-dependencies.json:
"my-vendor/elm-lib": "0.0.1"
Clearly, all of the above should be taken care of automatically by elm-package, if only I could point it at /my-lib/ from /my-app/. So how do I do that?
Easier use of local packages is on the todo list. I'm afraid your current approach is the state of the art. Either do it like your doing it now or copy over the code from the package (or maybe symlink modules folders/.elm files from my-lib/src in my-app/src?)
Most recent thread on the mailing list about this issue: https://groups.google.com/d/topic/elm-discuss/i51Bor6Uers/discussion
In 2017 ( elm 0.18 ) you can do the following:
Overwrite a published package with a local cloned version
If you've got a dependency to a published package that you'd like to make local, remove your dependency e.g:
"dependencies": {
"rtfeldman/elm-css": "8.2.0 <= v < 9.0.0"
}
Then do a elm-make of your project (this should remove the package from your elm-stuff directory otherwise it will use the cached version of the package. Then you clone and reference the package locally as per steps below.
Reference a local package
You can reference any elm project locally by adding it to source-directories like this:
"source-directories": [
".",
"src",
"../elm-css/src"
],
Add the locally referenced package's dependencies to your elm-package.json
elm-css has these dependencies:
"rtfeldman/elm-css-util": "1.0.2 <= v < 2.0.0",
"rtfeldman/hex": "1.0.0 <= v < 2.0.0"
So add these to your elm-package.json as well.
You're done!
You can track the status of this feature in this enhancement request.
来源:https://stackoverflow.com/questions/28110810/using-local-packages