Manage where your dependencies should live from
your dependencies are automatically symlinked according to configuration,
eliminating the need for extra code that just moves files around. Need hard
links? That’s cool too.
Hang on. My task runner already does this.
If your task runner’s only role in your workflow is to move files around, you’re essentially using a Jaeger to pick up a pebble. If you use a task runner to do more than just that, consider whether defining a non-standard location for your dependencies should be done in your task runner config or in your package manager config.
npm install --save-dev symdeps
Add something like this to your
// package.json"symdeps":"paths":"public/js/vendor": "jquery" "mediaelement"
symdeps from an npm script, like
// package.json"scripts":"postinstall": "symdeps"
Now every time a dependency is installed,
symdeps will create symbolic links
public/js/vendor/ directory like this:
// relative to project root public/js/vendor/jquery public/js/vendor/mediaelement
symdeps will create any directories that don’t already exist along the base
public/js/vendor in the example above). Also note that if the
destination already exists (whether it be a file, symlink, or directory) it
will be replaced with the symlink.
Linking files directly
You can target individual files quite simply like so:
This will symlink these dependencies like this:
// relative to project root public/js/vendor/jquery.min.js public/js/vendor/mediaelement-and-player.min.js
Linking scoped dependencies
If you’re installing a dependency that’s scoped (e.g.
symdeps will symlink the library name directly (excluding the scope segment
in the package name). So adding
@project/library to the path array in the
examples above would result in a symlink at:
Using hard links
Depending on your workflow, you might want to use hard links instead of
symbolic links. This is particularly useful if your deployment process does not
install dependencies on the remote (you might push a built artifact, for
example), or if you want to track front-end dependencies in version control but
don’t want to track everything in
node_modules. You can make
hard links by setting
"hard": true in your
package.json’s symdeps config,
or by using the
--hard flag from the command line.
- Create relative links. The ability to generate symbolic links whose target paths are relative to the location of the link instead of absolute. This is useful in the creation of deployment artifacts or when otherwise moving the application root somewhere.