Giter Club home page Giter Club logo

vendor-copy's Introduction

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.

vendor-copy's People

Contributors

qubyte avatar jacktonkin avatar lcapel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.