How to do equivalent of npm install --save with dub?

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 13 05:29:17 PST 2015


On 1/13/2015 10:01 AM, Andrew Grace wrote:
> I am trying to play with D, but I'm getting stuck with the DUB package
> manager.  If use DUB to download a package to my project, how do I get
> DUB to add what I downloaded to the dub.json file? I have tried DUB
> --fetch --cache=local http-parser (for example).  It downloads the
> package, but then nothing is added to the list of dependencies.
>
> I'd appreciate any help.

As Rikki said, you don't need to download anything. You've got it rather 
backwards. *You* add the dependency to the dub.json and then *DUB* will 
pull it down and compile it automatically when you execute 'dub' or 'dub 
build' in the same directory as the configuration file.

See the dub.json at [1] as an example. It's a simple little TicTacToe 
game that has a dependency on DerelictSDL2, which, if you look at [2], 
you'll find has a dependency on DerelictUtil. If you clone the source, 
cd into the top-level directory and execute 'dub', then DUB will pull 
down both DerelictUtil and DerelictSDL2, compile them into libraries, 
compile the game code, then link it with the libraries and run the 
executable.

[1] https://github.com/aldacron/t3/blob/master/dub.json
[2] https://github.com/DerelictOrg/DerelictSDL2/blob/master/package.json


More information about the Digitalmars-d-learn mailing list