Code Monkey home page Code Monkey logo

rollup-plugin-copy's Introduction

rollup-plugin-copy

Build Status Codecov

Copy files and folders, with glob support.

Installation

# yarn
yarn add rollup-plugin-copy -D

# npm
npm install rollup-plugin-copy -D

Usage

// rollup.config.js
import copy from 'rollup-plugin-copy'

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/app.js',
    format: 'cjs'
  },
  plugins: [
    copy({
      targets: [
        { src: 'src/index.html', dest: 'dist/public' },
        { src: ['assets/fonts/arial.woff', 'assets/fonts/arial.woff2'], dest: 'dist/public/fonts' },
        { src: 'assets/images/**/*', dest: 'dist/public/images' }
      ]
    })
  ]
}

Configuration

There are some useful options:

targets

Type: Array | Default: []

Array of targets to copy. A target is an object with properties:

  • src (string Array): Path or glob of what to copy
  • dest (string Array): One or more destinations where to copy
  • rename (string Function): Change destination file or folder name
  • transform (Function): Modify file contents

Each object should have src and dest properties, rename and transform are optional. globby is used inside, check it for glob pattern examples.

File
copy({
  targets: [{ src: 'src/index.html', dest: 'dist/public' }]
})
Folder
copy({
  targets: [{ src: 'assets/images', dest: 'dist/public' }]
})
Glob
copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }]
})
Glob: multiple items
copy({
  targets: [{ src: ['src/index.html', 'src/styles.css', 'assets/images'], dest: 'dist/public' }]
})
Glob: negated patterns
copy({
  targets: [{ src: ['assets/images/**/*', '!**/*.gif'], dest: 'dist/public/images' }]
})
Multiple targets
copy({
  targets: [
    { src: 'src/index.html', dest: 'dist/public' },
    { src: 'assets/images/**/*', dest: 'dist/public/images' }
  ]
})
Multiple destinations
copy({
  targets: [{ src: 'src/index.html', dest: ['dist/public', 'build/public'] }]
})
Rename with a string
copy({
  targets: [{ src: 'src/app.html', dest: 'dist/public', rename: 'index.html' }]
})
Rename with a function
copy({
  targets: [{
    src: 'assets/docs/*',
    dest: 'dist/public/docs',
    rename: (name, extension, fullPath) => `${name}-v1.${extension}`
  }]
})
Transform file contents
copy({
  targets: [{
    src: 'src/index.html',
    dest: 'dist/public',
    transform: (contents, filename) => contents.toString().replace('__SCRIPT__', 'app.js')
  }]
})

verbose

Type: boolean | Default: false

Output copied items to console.

copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  verbose: true
})

hook

Type: string | Default: buildEnd

Rollup hook the plugin should use. By default, plugin runs when rollup has finished bundling, before bundle is written to disk.

copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  hook: 'writeBundle'
})

copyOnce

Type: boolean | Default: false

Copy items once. Useful in watch mode.

copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  copyOnce: true
})

copySync

Type: boolean | Default: false

Copy items synchronous.

copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  copySync: true
})

flatten

Type: boolean | Default: true

Remove the directory structure of copied files.

copy({
  targets: [{ src: 'assets/**/*', dest: 'dist/public' }],
  flatten: false
})

All other options are passed to packages, used inside:

Original Author

Cédric Meuter

License

MIT

rollup-plugin-copy's People

Contributors

bertday avatar cpatchane avatar j3l11234 avatar meuter avatar mstssk avatar piscium2010 avatar shahzainb avatar spudmashmedia avatar vladshcherbin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rollup-plugin-copy's Issues

Rename does not let me alter the folder to which the file is written.

I have tried various rename suggestions in order to remove the top level folder from being copied over, but rename only seems to affect the filename itself, and not the destination folders.

For example:

        copy({
            flatten: false,
            targets: [
                {
                    src: "resources/assets/**/*",
                    dest: "public",
                    rename: (name, extension, fullPath) => {
                        return "../" + fullPath.split(path.sep).slice(2).join(path.sep);
                    },
                },
            ],
            verbose: true,
        }),

My goal is to copy the content into public, not public/assets (which is the default behavior). Various issues in the repo recommend using rename to achieve this. Unfortunately this only works at the first level, not in multi-level globs with nested directories. You can see by the output that nested folders are repeated, instead of traversing up a folder:

  resources/assets/android-chrome-192x192.png → public/android-chrome-192x192.png [R]
  resources/assets/android-chrome-512x512.png → public/android-chrome-512x512.png [R]
  resources/assets/apple-touch-icon.png → public/apple-touch-icon.png [R]
  resources/assets/favicon-16x16.png → public/favicon-16x16.png [R]
  resources/assets/favicon-32x32.png → public/favicon-32x32.png [R]
  resources/assets/favicon.ico → public/favicon.ico [R]
  resources/assets/fonts → public/fonts [R]
  resources/assets/images → public/images [R]
  resources/assets/js → public/js [R]
  resources/assets/logo-mark.png → public/logo-mark.png [R]
  resources/assets/site.webmanifest → public/site.webmanifest [R]
  resources/assets/images/cash-for-whatever → public/assets/images/cash-for-whatever [R]
  resources/assets/images/email → public/assets/images/email [R]
  resources/assets/images/pages → public/assets/images/pages [R]
  resources/assets/images/transparent.png → public/assets/images/transparent.png [R]
  resources/assets/fonts/Raleway-Italic.ttf → public/assets/fonts/Raleway-Italic.ttf [R]
  resources/assets/fonts/Raleway.ttf → public/assets/fonts/Raleway.ttf [R]
  resources/assets/js/ckeditor5 → public/assets/js/ckeditor5 [R]
  resources/assets/images/cash-for-whatever/logo.png → public/assets/images/images/cash-for-whatever/logo.png [R]
  resources/assets/images/email/envelope-solid.png → public/assets/images/images/email/envelope-solid.png [R]
  resources/assets/images/email/full_logo-original.png → public/assets/images/images/email/full_logo-original.png [R]
  resources/assets/images/email/full_logo.png → public/assets/images/images/email/full_logo.png [R]
  resources/assets/images/email/phone-rotary-solid.png → public/assets/images/images/email/phone-rotary-solid.png [R]
  resources/assets/images/email/signature.html → public/assets/images/images/email/signature.html [R]
  resources/assets/images/pages/404.png → public/assets/images/images/pages/404.png [R]
  resources/assets/images/pages/500.png → public/assets/images/images/pages/500.png [R]
  resources/assets/images/pages/forgot-password.png → public/assets/images/images/pages/forgot-password.png [R]
  resources/assets/images/pages/login.png → public/assets/images/images/pages/login.png [R]
  resources/assets/images/pages/register.jpg → public/assets/images/images/pages/register.jpg [R]
  resources/assets/images/pages/reset-password.png → public/assets/images/images/pages/reset-password.png [R]
  resources/assets/images/pages/vuexy-login-bg.jpg → public/assets/images/images/pages/vuexy-login-bg.jpg [R]
  resources/assets/js/ckeditor5/ckeditor.js.map → public/assets/js/js/ckeditor5/ckeditor.js.map [R]
  resources/assets/js/ckeditor5/ckeditor.jsx → public/assets/js/js/ckeditor5/ckeditor.jsx [R]

Up until resources/assets/site.webmanifest → public/site.webmanifest [R] everything is correct, after that everything is incorrect, because it once again includes the assets subfolder.

(I tried without "../" and that didn't work at all.)

Any suggestions on how to address this?

Possibly related issues:
#32
#56

Move `@types/*` to `devDependencies`.

I'm using this plugin to build a library for the browser. The library uses typescript checking, so it also loads type definitions for node. Some types has conflicts.

Publish

The source would suggest you have added support for using globs syntax to describe targets, when will this be published?

ongenerate hook is deprecated

rollup-plugin-copy plugin: The ongenerate hook used by plugin rollup-plugin-copy is deprecated. The generateBundle hook should be used instead

copy occurs before generated bundle write when multi entry

export default [
  {
    input: 'src/main.ts',
    output: {
      sourcemap: false,
      file: `dist/music-v${version}.min.js`,
      format: 'umd',
      plugins: [
        terser(),
      ],
    },
    plugins: [
        ...makeBasicPlugins({}),
        license({
          banner: {
            content: {
              file: 'LICENSE.md',
              encoding: 'utf-8',
            },
          },
        }),
        copy({
          verbose: true,
          hook: '',
          targets: [
            {
              // eslint-disable-next-line no-undef
              src: path.join(__dirname, `dist/music-v${version}.min.js`),
              // eslint-disable-next-line no-undef
              dest: path.join(__dirname, '../backend/public/js')
            }
          ]
        })
    ],
  },
  {
    input: 'src/main.ts',
    output: {
      sourcemap: true,
      file: `dist/music.debug.js`,
      format: 'umd',
    },
    plugins: [
      ...makeBasicPlugins({ sourceMap: true, NODE_ENV: 'debug' }),
      copy({
        verbose: true,
        targets: [
          {
            // eslint-disable-next-line no-undef
            src: path.join(__dirname, 'dist/music.debug.js'),
            // eslint-disable-next-line no-undef
            dest: path.join(__dirname, '../backend/public/js')
          },
          {
            // eslint-disable-next-line no-undef
            src: path.join(__dirname, 'dist/music.debug.js.map'),
            // eslint-disable-next-line no-undef
            dest: path.join(__dirname, '../backend/public/js')
          },
        ]
      })
    ],
  },
];

First clean both copy source and target directory, Then run rollup command, got

$ cross-env NODE_ENV=production rollup -c rollup.config.js

src/main.ts → dist/music-v0.0.1.min.js...
created dist/music-v0.0.1.min.js in 6.9s

src/main.ts → dist/music.debug.js...
no items to copy
created dist/music.debug.js in 4.4s
✨  Done in 12.37s.
✨  Done in 12.68s.

result is not stable

Is there the ability to transform the files within the input directory?

Per the documents, the transform property is set on a specific target via input

Is there a way to get this functionality? or would the plugin need to be amended to compensate for the functionality?
If it is the later, are you aware of such package?
Would i need to create a pull request to amend if need be?

Thanks

Error when copying multiple directories to the same nonexistent directory

Related issue #7 #9 .

Running rollup with the following config produces this error:

index.js → dist/bundle.js...
[!] (copy plugin) Error: EEXIST: file already exists, mkdir 'dist'
Error: EEXIST: file already exists, mkdir 'dist'
{
  "rollup": "^1.11.2",
  "rollup-plugin-copy": "^2.0.0"
}
import copy from "rollup-plugin-copy";
export default {
  input: "index.js",
  output: {
    file: "dist/bundle.js",
    format: "cjs"
  },
  plugins: [
    copy({
      targets: {
        "dir-1": "dist",
        "dir-2": "dist"
      }
    })
  ]
};

Edit:
Only happens when dist/ does not exist.

Promise support

Would it be possible for src to accept string | readonly string[] | Promise<string[]>?
I'm trying to use copy with npm-packlist

Feature request: Add "ignore" option for inverted use

If I know that I'm using Rollup to convert .vue, .js and .css files, I'd like to be able to copy everything else to the output dir:

copy({
  targets: [
    { src: 'src/**', dest: 'public', ignore: ['*.vue', '*.js', '*.css'] }
  ]
})

Clash with `rollup-plugin-typescript2`?

I created a barebones project with Typescript.

tsconfig.json
{
  "compilerOptions": {
    "target": "es6",
    "module": "esnext",
    "rootDir": "./src",
    "strict": true,
     "esModuleInterop": true
  }
}
package.json
  "devDependencies": {
    "rollup": "^1.9.3",
    "rollup-plugin-copy": "^1.0.0",
    "rollup-plugin-typescript2": "^0.20.1",
    "typescript": "^3.4.3"
  }

With src/index.html and src/index.ts present, I am getting the following error.

[!] (rpt2 plugin) Error: Unknown object type "asyncfunction"
src/index.ts
Error: Unknown object type "asyncfunction"
    at Object._object (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23691:17)
    at Object._function (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23792:14)
    at Object.dispatch (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23658:30)
    at /home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23719:18
    at Array.forEach (<anonymous>)
    at Object._object (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23715:21)
    at Object.dispatch (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23658:30)
    at /home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23733:23
    at Array.forEach (<anonymous>)
    at Object._array (/home/lazar/basketball/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:23732:20)

1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here's the config.

import typescript from 'rollup-plugin-typescript2'
import copy from 'rollup-plugin-copy'

export default {
  input: 'src/index.ts',
  output: {
    file: 'dist/bundle.js',
    format: 'iife',
  },
  plugins: [
    copy({
      targets: [
        'src/index.html',
      ],
      outputFolder: 'dist',
    }),
    typescript({
      typescript: require('typescript'),
    }),
  ]
}

Commenting out any of the plugins make it work properly. This error was mentioned in ezolenko/rollup-plugin-typescript2#105, but the rationale given seems irrelevant to this issue.

Transform doesn't work without Rename

Hi. Thanks for all the hard work on this project!

Heads up! I tried to use the transform capability. Didn't quite work unless I also use rename.

In case it helps, I'm also using the rollup-plugin-multi-input plugin. I don't know if this is related.

image

I'm able to use this plugin, so this may or may not be super urgent. Thanks!

Don't overwrite existing file

I currently generate a lot of google functions from typescript via rollup. Some have exceptions in terms of how they are deployed which makes me bundle an env file; but I would like to only do so if the env file doesn't already exist.

I'd like to make the case for a clause that copies file only if the destination doesn't exist. If there's interest I can have a look at writing it. Thoughts?

Folder Hierarchy not preserved

Hi,

I'm using a glob filter like this: packages/my-package/src/**/*.css and I was expecting that the folder hierarchy will be preserved. I'm using it to bundle my css using imports.

Cheers.

folder hierarchy not preserved (again)

Hi, I know this has been asked before but I couldn't find a solution.
I have this folder structure:

- /myapp/src/assets/
----- file1.svg
----- icons/
--------- icon1.svg
--------- icon2.svg

And when I use the plugin like this:

		copy({
			targets: [
				{
					src: 'src/assets/**/*',
					dest: 'public/build/assets',
					flatten: true,
				},
			]
		}),

I expect to have this:

- /myapp/public/build/assets/
----- file1.svg
----- icons/
--------- icon1.svg
--------- icon2.svg

But instead I have this:

- /myapp/public/build/assets/
----- file1.svg
----- icon1.svg
----- icon2.svg
----- icons/
--------- icon1.svg
--------- icon2.svg

Is that a bug? If not, what did I miss?

Copy just one time

It would be amazing to copy just one time.

Example: I need to copy just the first time my npm run dev start all the files from public folder to dist.

Every time I change a .js file I don't need to copy again the files from public to dist.

Is there a way?

Update Instructions: Run 'copy' after bundle created

Thank you for plugin that only made my simple task 'Copy After Bundle was created' working.
Please add into documentation where you talking about default hook information that hooks should be taken from https://rollupjs.org/guide/en/#plugin-development and if we need to run 'copy' after bundle was made and written to drive, we need to use writeBundle hook like so copy({hook:'writeBundle',[..]})

And better to start your description that by default plugin runs before bundle was written to disk due default hook named 'buildStart'

To get into that point i spend a lot of time and was almost ready to write my own plugin because after one hour of digging into api i understand how it works now lol - it is good for me but thats the purpose of work you have done >> to just plug it in without any googling

Build Directory Structure different from Original even if flatten is false

The build directory structure is different from the original one resulting in 404 (Not Found) errors in browser.

image

This is my rollup-config.js file:

`const copy = require('rollup-plugin-copy');
const { createDefaultConfig } = require('@open-wc/building-rollup');
const merge = require('deepmerge');
const { injectManifest /* generateSW */ } = require('rollup-plugin-workbox');

const basicConfig = createDefaultConfig({
input: './index.html',
output: {
file: 'dist/app.js',
format: 'cjs'
},
plugins: {
workbox: false,
},
});

const workboxConfig = require('./workbox-config.js');

export default merge(basicConfig, {
plugins: [
injectManifest(workboxConfig),
copy({
targets: [
{
// copy over jpg image files
src: '/*.jpg',
dest: 'dist',
},
{
// copy over png images files
src: '
/.png',
dest: 'dist',
},
{
src: 'assets/**/
.*',
dest: 'dist',
},
{
// copy manifest.webmanifest
src: 'manifest.json',
dest: 'dist',
},
],
hook: 'buildStart',
flatten: false
}),
],
});
`

workbox-config.js

`const path = require('path');

module.exports = {
swDest: path.join(__dirname, 'dist', 'sw.js'),
swSrc: path.join(__dirname, 'sw.js'),
globDirectory: path.join(__dirname, 'dist'),
globPatterns: ['**/*.{html,js,css,json}']
};
`

sw.js

`
import {precacheAndRoute} from 'workbox-precaching';

precacheAndRoute(self.__WB_MANIFEST);
`

Any ideas on what can cause the issue is welcome. Thank, you.

Create symlink instead of copy?

It would be nice if I could create a symlink to a file or directory. If this makes sense you could implement that as well (since I'm not experienced enough to do it). Or create a new repo and package.

Thanky for your lib!

First directory stripped when flatten is false

Followup from #36

The new flatten option when set to false doesn't work as expected. The first directory is stripped so the new directory structure doesn't represent the original directory structure.

A workaround is to add the directory name manually in the destination, but that doesn't work if the parent directory is a glob as well.

Not working well in a Laravel project using Vite

Using

  • Laravel v9.30
  • vite v3.1.0
  • rollup-plugin-copy v3.4.0

Issue

I'm using the plugin in a Laravel project with Vite.

I have this part of code inserted in the vite.config.js file:

copy({ 
  targets: [{
      src: 'resources/themes/xpto',
      dest: 'public/build/assets'
  }],
  flatten: true,
  copyOnce: true,
  verbose: true,
}),

When i run the command npm run dev the plugin seems to not do anything, nothing is copied, but then if i change something in the vite.config.js file the vite watcher executes again automatically and this time the plugin works as expected and the folder is copied:

[vite] vite.config.js changed, restarting server...
copied:

  /var/www/html/resources/themes/xpto→ /var/www/html/public/build/assets/xpto
[vite] server restarted.

So far i haven't figured out how to make it work at first instruction. I tried a couple different hooks too, but to no avail.

Any ideas? Thanks.

`rename` option does not work in Rollup 4

After upgrading to Rollup 4, a target that uses rename option will not be copied, it fails silently.

I'm using it like this:

      copy({
        targets: [
          { src: 'dist/index.d.ts', dest: 'dist', rename: 'index.d.mts' },
        ],
      }),

Note that it also does not work if I try a different target directory.

Thanks!

Copying entire directory excluding file extension

Hi, I'm trying to copy the /src/profiles folder into /dist and it works very well, but wat I'm trying to do is excluding all the .tsx files inside the /src/ subfolder. Is it possible to do something like this with this plugin?

I tried with

copy({ targets: [{ src: ['src/profiles', '!**/*.tsx'], dest: 'dist' }] })

as stated in the readme.md but nothing seems to work.

Support rollup's watch mode

When running rollup in watch mode, if a change is made to a copied asset, the modified asset should be copied again to the target directory. Right now one has to kill the watch process and re-run it for the copy to be done. It breaks the "mental flow" of development since one has to constantly remember that changes made to the edited buffer are not propagated automatically, unlike other sources. How many times have I reloaded the web page, wondered why it's not working, before realizing I forgot to kill the watch process and rerun it?

Use another user group instead of root

I found out that the copied file was created by root instead of my current user group, and that causes I can not delete the file with out sudo.

code:

        copy({
            targets: [{src: 'build/static/god/template.html', dest: 'build/test', rename: 'index.html'}],
        })

and when I want to remove the files I got:

Failed to compile.

EACCES: permission denied, unlink '/Users/monkeyfigaro/workspace/sohu-inc/awesome-sohu/build/test/index.html'


error Command failed with exit code 1.

See the user groups:

image

Change Async to Sync, and add option when do job

    ongenerate: function (object) {
      for (let key in options) {
        if (key == "verbose") continue;
        const src = key;
        const dest = options[key];
        try {
          fse.copySync(src, dest)
          if (verbose) success(name, src, dest);
        } catch (err) {
          fatal(name, src, dest, err);
        }
      }
    }```

and second - make possible execute that after files is generated, or inplace.. 
it is usefull when You would like first copy some files, and then apply some (text replacement on those files)

Upgrade fs-extra

Seems a new major version of fs-extra was released recently. It would be great to upgrade.

Error thrown if there is no `dist` directory

  • NPM: 5.6.0
  • Node: `8.6.0
  • OS: MacOS Sierra 10.12.6
  • Rollup : 0.52.0
  • Rollup Plugin Copy: 0.2.3

When I run npm run build and there is no dist directory I get this error;

(rollup-plugin-copy) 'src/css/badger-accordion.css' -> 'dist/badger-accordion.css' (✘)

    Error: ENOENT: no such file or directory, chmod 'path/to/plugin/badger-accordion/dist/badger-accordion.css'
npm ERR! code ELIFECYCLE
npm ERR! errno 254

Sometimes I get the error twice... It still copies the files over so it works just it's throwing an error... Thanks for making this plugin it's just what I needed! Let me know if I can help getting this fixed.

No error if target file does not exist

E.g.

    copy({
      targets: [
        { dest: 'lib/', src: 'boguspath/index.html' },
      ],
    }),

Assuming boguspath doesn't exist, I get no error (or warning) when building. This should be standard and/or at the very least an option.

Replace in file

It would be amazing to replace some vars in files using something like https://github.com/adamreisnz/replace-in-file.

Example:

  • I have the index.html in public folder
  • I start with npm run dev
  • This plugin copy index.html from public to dist
  • After the copy or in memory change the %BundleNameVarFromRollup% value in <script src="/%BundleNameVarFromRollup%.js"/>

Is it possible?

Compile typescript

Hi,

thanks for this great plugin! Do you have a solution to not only copy, but also compile ts files?
Let's say existing js files should be copied to the destination folder and ts files should first be compiled and then copied.

Thanks a lot!
Dominic

[Feature] Autodetect dist folder

Currently I need to prepend every dest field with dist/ folder, so I do duplicate where I plan to output files in several places (dest fields and output options of rollup).

Rollup has outputOptions hook which can be used to obtain directory from that options. So, I don't need to duplicate it.

There are 2 possible cases:

  1. when output.file is specified - dirname(ouput.file)
  2. when output.dir is specified - just use this dir as a root path.

Error: EEXIST: file already exists

Given the following config:

copy({
    targets: [{ src: ["dist", "package.json"], dest: "testing" }],
    hook: "writeBundle",
    verbose: true,
  });

I'm getting the following error. The files are been copied though.

rollup v2.7.2
bundles src/index.tsx → dist/index.cjs.js, dist/index.esm.js...
copied:
copied:
[!] (plugin copy) Error: EEXIST: file already exists, mkdir 'testing/dist'
Error: EEXIST: file already exists, mkdir 'testing/dist'

  dist → testing/dist
  package.json → testing/package.json

Correction required for npm install command documentation

Hi @meuter ,

Thanks for adding this plugin!

There is a minor correction required in the npm install command given in the installation step in the documentation.

npm install rollup-copy-plugin to be corrected to npm install rollup-plugin-copy.

Also, I have been wondering if there is an option to copy the generated files after they are added to dest folder ? As a workaround, I am using rollup-plugin-execute to execute the shell command to copy files.

Thanks!

Negated patterns doesn't work correctly.

rollup: v2.50.5
rollup-plugin-copy: v3.4.0


code:

copy({
  targets: [
    {
      src: [`${srcDir}/images/**/*`, `!**/*.md`],
      dest: `${distDir}/images`,
    },
  ],
}),

${srcDir}/images:

images
  ├README.md
  └ test
     ├ README.md
     └ test
        └ README.md

Actual result

${distDir}/images:

images
 └ test
    ├ README.md
    └ test
       └ README.md

Expected result

${distDir}/images is empty.

Has anyone been able to get this working in Sveltekit yet?

I have my config in config.kit.vite.plugins in the svelte.config.js file just as it was on rollup.config.js but the plugin seems to be missing some configuration to actually copy the files.

I tried asking in the Sveltkit Discord without a lot of luck. Has anyone gotten this working yet?

copy folder structure with flatten=false and ignore first levels

I need to copy a folder structure (so flatten=false is necessary), but do not want to have the full path in destination.

Example:

targets:[{
    src: 'folder1/folder2',
    dest: 'destfolder'
}];

If the folder1/folder2 structure looks like this:

folder3.1/a.txt
folder3.2/folder3/b.txt

I need this in destination folder:

destfolder/folder3.1/a.txt
destfolder/folder3.2/folder3/b.txt

Instead, I get this (since the source folder gets copied in addition except the first one):

destfolder/folder2/folder3.1/a.txt
destfolder/folder2/folder3.2/folder3/b.txt

Is this possible with the copy plugin at all?

Transform only works on first instance of file

I have a file with multiple instances of the same placeholder text but only the first is transformed, chaining multiple instances fixes it but I wonder if it's possible to replace all instances in one run?

// file to copy + transform
<!DOCTYPE html>
<html lang="en">
  <head></head>
  <body>
    <div>__EXT_VERSION__</div> <!-- Without the chaining below, only this one is transformed -->
    <div>__EXT_VERSION__</div>
    <div>__EXT_VERSION__</div>
  </body>
</html>
function setVersion(contents, filename) {
  return contents.toString()
   // You have to call this as many times as __EXT_VERSION__ appears in a file
    .replace('__EXT_VERSION__', pkg.version)
    .replace('__EXT_VERSION__', pkg.version)
    .replace('__EXT_VERSION__', pkg.version)
);
}

...
copy({
  targets: [
    { src: "index.html", dest: "./", transform: setVersion },
  ],
}),

Wildcard support

Hi! thank you for nice plugin,
is there any plan to support wildcards to achieve something like below?

 { files: './docs/!*.html', dest: './docs/dist' },
 { files: './docs/robots.txt', dest: './docs/dist' },
 { files: './docs/assets/favicon/!*.*', dest: './docs/dist' },
 { files: './docs/assets/images', dest: './docs/dist/assets/images' },
 { files: './docs/assets/styles', dest: './docs/dist/assets/styles' },

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.