npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vendor-copy

v3.0.1

Published

A utility to copy client-side dependencies into a folder.

Downloads

6,665

Readme

vendor-copy

A utility to copy client-side dependencies into a folder. It looks for a vendorCopy field in your package.json, which contains an array of objects, each with a to and from field, which are paths relative to the package.json file.

npm script Usage

The CLI looks for configuration in a package.json file. It assumes that it's being run from the same directory as the package file. This makes it ideal to use as an npm script in the package file. For example (note in particular the postinstall script):

{
  "scripts": {
    "preinstall": "rimraf public/vendor"
    "postinstall": "vendor-copy"
  },
  "dependencies": {
    "someDependency": "1.0.0",
    "someOtherDependency": "0.1.2",
    "vendorCopy": "1",
    "rimraf": "2"
  },
  "devDependencies": {
    "someDevelopmentDependency": "4.3.2"
  },
  "vendorCopy": [
    {
      "from": "node_modules/someDependency/someDependency.js",
      "to": "public/vendor/someDependency.js"
    },
    {
      "from": "node_modules/someOtherDependency/someOtherDependency.js",
      "to": "public/vendor/someOtherDependency.js"
    }
  ],
  "devVendorCopy": [
    {
      "from": "node_modules/someDevelopmentDependency/someDevelopmentDependency.js",
      "to": "public/vendor/someDevelopmentDependency.js"
    }
  ]
}

When npm install is used and has completed the installation of both dependencies and development dependencies, it will copy items listed in "vendorCopy" and "devVendorCopy". When run in production mode, i.e. when the NODE_ENV environment variable is production or when npm in invoked with the --production flag, only items in vendorCopy are copied. In both cases rimraf has been used to delete the public/vendor to ensure a clean copy.

JS API

const vendorCopy = require('vendor-copy');

const promise = vendorCopy(root, copyItems);

  • root is an absolute base path.
  • copyItems is an array of objects with from and to file paths.

root is prepended to all from and to paths. Each from resolves to a file or directory, and will be copied to the to location. Intermediate directories will be created as required.

The returned promise resolves when copying is complete. The resolution value is an array like copyItems, but each from and to field is an absolute path.