Copy Watched

Laravel Mix extension to provide copy method that watches for changes, additions and deletions.
latest v3.0.0 - released
dsktschy
1868 downloads last week
MIT license
23 versions
copy
watch

Laravel Mix Copy Watched npm version GitHub license

This extension provides a copy method that can watch for not only changes but also additions and deletions.

Installation

With [email protected]>=6

$ npm install --save-dev laravel-mix-copy-watched

With [email protected]<6

$ npm install --save-dev [email protected]

Usage

const mix = require('laravel-mix')

require('laravel-mix-copy-watched')

mix.copyWatched(
  'src/images',
  'dist/images',
  { base: 'src/images' }
)

API

copyWatched(from, to, options)

This method has the same usage as the copy and copyDirectory methods.

from

Type: string | string[]

Paths or glob patterns to files and directories to be copied.

mix.copyWatched('from.png', 'to')
mix.copyWatched('from/**/*.txt', 'to', { base: 'from' })
mix.copyWatched('from/**/*.{jpg,jpeg,png,gif}', 'to', { base: 'from' })
mix.copyWatched(['from1.jpg', 'from2.webp'], 'to')

to

Type: string

Destination path for copied files and directories.

options

Type: object

Contains the following properties.

base

Type: string
Default: ''

When a path to a directory is set, the directory will be copied with the hierarchical structure kept.

// src/images/foo.png -> dist/foo.png
mix.copyWatched(
  'src',
  'dist'
)

// src/images/foo.png -> dist/images/foo.png
mix.copyWatched(
  'src',
  'dist',
  { base: 'src' }
)
dot

Type: boolean
Default: false

If set to true, files and directories whose names start with a dot will be copied.

// src/.foorc -> No output
mix.copyWatched(
  'src',
  'dist',
  { base: 'src' }
)

// src/.foorc -> dist/.foorc
mix.copyWatched(
  'src',
  'dist',
  {
    base: 'src',
    dot: true
  }
)

copyDirectoryWatched(from, to, options)

This method is an alias for the copyWatched method.