Giter VIP home page Giter VIP logo

rollup-plugin-cpy's Introduction

rollup-plugin-cpy

JavaScript Style Guide code style: prettier MIT License npm version

Rollup plugin to easily copy files and folders.

Installation

  • yarn
yarn add -D rollup-plugin-cpy
  • npm
npm i -D rollup-plugin-cpy

Usage

This plugin uses cpy by @sindresorhus.

All the options map to the cpy package apart from verbose.

It takes a config object

{
  files: string | glob | Array<string & glob>
  dest: string,
  options: {
    verbose: boolean,
    ...restOptions
  }
}

The verbose option if set to true print out each file copying log on console.

restOptions are same as options passed to cpy

import copy from 'rollup-plugin-cpy'

...

plugins: [
  ...
  copy({
    files: ['src/*.png', '!src/goat.png'],
    dest: 'dist',
    options: {
      verbose: true,
      ...
    }
  })
]

...

It can also take an array of above mentioned config object

import copy from 'rollup-plugin-cpy'

...

plugins: [
  ...
  copy([
        { files: 'src/**/*.png', dest: './dist/images' },
        { files: 'src/**/*.mp3', dest: './dist/audio' },
        { files: 'src/**/*.webm', dest: './dist/video' },
      ]),
]

...

License

This project is licensed under the MIT license.

rollup-plugin-cpy's People

Contributors

dependabot-preview[bot] avatar paulmelnikow avatar shrynx avatar xboston avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

deiteris

rollup-plugin-cpy's Issues

Mkdirp Does not Consider CWD

Was having issues with this line with this plugin trying to run mkdirp. Here's the offending line:
https://github.com/paulmelnikow/rollup-plugin-cpy/blob/master/src/index.js#L28

Example

copy({
  files: "**/*.png",
  dest: '../dist',
  options: {
    cwd: path.join(__dirname, 'src'),
    parents: true
  }
});

This is trying to copy all images in src and copy them to dist, but maintaining the folder structure. The directory that should be created is resolve(dest, options.cwd) not dest. In this case, the plugin with create a folder one directory above, but cpy will copy fine. Maybe this mkdirp isn't even needed here since it seems to be handled by cpy.

Files are copied too late

Hi,

We're running into an issue when using rollup-plugin-cpy with rollup-plugin-workbox. The workbox plugin will run at the writeBundle hook, and so does the cpy plugin. The problem here is that if it takes longer for the cpy plugin to copy files, workbox will be done before files are copied, meaning that workbox will not add some files to the precache manifest.

See some example code here:

module.exports = {
  input: 'index.js',
  output: {
    format: 'esm',
    dir: 'dist'
  },
  plugins: [
    copy({
      files: 'img/*.png',
      dest: 'dist',
    }),
    injectManifest({
      swDest: path.join(__dirname, 'dist', 'sw.js'),
      swSrc: path.join(__dirname, 'sw.js'),
      globDirectory: path.join(__dirname, 'dist'),
      globPatterns: ['**/*.{html,js,css,png}'],
    }),
  ],
};

Result:

The service worker file was written to /Users/au87xu/rollup-workbox-img-bug/dist/sw.js
The service worker will precache 1 URLs, totaling 26 B.

Only 1 URL is precached, because workbox finishes before the files are copied. I'd expect 2 URLS to be precached; dist/index.js and dist/img.png.

As I understand correctly from reading the source code of rollup-plugin-cpy, nothing in rollup-plugin-cpy depends on anything during the entire rollup process, all it does is simply copy files from a source directory, to the build directory.

This means that we could potentially solve this problem by starting the copy process to the buildStart hook, so we have a guarantee that the files will be copied by the time the writeBundle hook starts, because (from my understanding) rollup will await the buildStart hooks before moving on.

This would mean a small code change on line 44:

+     async writeBundle() {
-      async buildStart() {

Would love to hear your thoughts about this, i'd be happy to make a PR ๐Ÿ˜Š

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.