codep

Copy your frontend dependencies directly into your assets.

Usage no npm install needed!

<script type="module">
  import codep from 'https://cdn.skypack.dev/codep';
</script>

README

CoDep

Copy your frontend dependencies directly into your assets.

Features

Install

npm i -D codep

Usage

import { Codep } from "codep"

await new Codep("assets/vendor", {
  exclude: ["jquery", "modernizr"]
}).paste()

API

const codep = new Codep(outDir, options?)

outDir

Type : string

Specify an output folder for all copied files

options

Type: object

Property Type Default Description
source string node_modules Specify the node modules directory
pkg string package.json Specify the json file location
flattenDist boolean true Keep the dist folder or flatten in the root folder from each dependency
exclude string\|array [] Specify the name of the dependencies you don't want to copy, e.g. ['jquery', 'modernizr']
ext string\|array Only copied files with the specified extension. Use * to grab all files from dependencies
overwrite boolean false Do you want to overwrite existing dependencies in the outdir?
devDependencies boolean false Should you need to grab devDependencies as well?

ext Default: js,jsx,ts,tsx,css,scss,less,stylus,map,eot,woff,woff2,ttf,svg,png,jpg,jpeg

codep.paste()

Write source files to outDir asynchronously.

;(async () => {
  await codep.paste()
})()

Optimizations

Handle progress reports the way you want.

import { Codep } from "codep"

// initialize Codep
const codep = new Codep("assets/vendor", {
  exclude: ["jquery", "modernizr"]
})

// handle reports or just ignore this block
codep.on("progress", data => {
  // doing things on progress
})

// copying
;(async () => {
  try {
    await codep.paste()
  } catch (error) {
    throw error
  }
})()

codep.on('progress', handler)

handler(data)

Type: Function

data

Type: Manifest

Manifest is an object with properties below:

Property Type
success number
failed number
processed number
percent string
vendors string[]
totalFiles number
log Log

Related