web icon indicating copy to clipboard operation
web copied to clipboard

[rollup-plugin-copy] 'dest' option

Open istvank opened this issue 4 years ago • 6 comments

As I understand from the docs, I should use '@web/rollup-plugin-copy' instead of 'rollup-plugin-copy'.

However, the 'original' does have a dest option to change the destination folder.

Do you plan to introduce the dest option, or should I use rollup-plugin-copy for my purposes? (Which is copying over i18next resource files from 'locales' folders.)

istvank avatar Oct 18 '20 12:10 istvank

What's your intention? To copy to a folder other than the rollup output directory?

LarsDenBakker avatar Oct 18 '20 12:10 LarsDenBakker

To give a bit more context, my rollup.config.js file currently has plugins: [copy({ patterns: '**/locales/**/*' })], ...which copies over all locales/** files to the rollup output directory, keeping the node_modules/component/locales/** structure. My goal would be to collect all files within a central locales directory. There is no ambiguity in the files or the threat of writing over files, as in the locales directories, I have a subfolder with the respective namespace.

istvank avatar Oct 18 '20 12:10 istvank

Personally I would like to see such an option too.

It's similar to https://www.npmjs.com/package/rollup-plugin-copy

The reason is that sometimes you want your folder structure to be different for your output as compared to your source. It's perhaps unusual from an idealistic perspective where you'd want your folder structure to remain fully intact and the same, but sometimes you want to copy a dependency asset from a node_modules dir into your dist/assets folder for example, so that they are available to your consumers.

To make it more concrete: I am building a design system library for my application developers. In my design system lib I have a dependency on company-branding package which has a bunch of assets. I want to make those assets available in my library directly, so before publishing to NPM I want to copy the assets from company-branding into my own assets (dist/assets). Then my users only need to rely on the design system lib and don't have to import assets from company-branding directly.

jorenbroekema avatar Oct 22 '20 08:10 jorenbroekema

you probably want to use https://modern-web.dev/docs/building/rollup-plugin-import-meta-assets/ instead as it will allow to permanently cache those files.

additionally, rollup will take care of where to actually place those files.

for the copy use case... why not "use" bash cp directly? as there would be no need to hook in any way into rollup? 🤔 e.g. something like

"scripts": {
  "build": "rollup && cp node_modules/foo/assets/* dist/assets"
}

PS: if you really want it to be copied within a rollup plugin then rollup-plugin-copy might even be better as it just does that under the hood (e.g. copy files directly not telling rollup about it) whereas @web/rollup-plugin-copy tells rollup "hey this file should be handled as well" (and then rollup actually does whatever it needs to do... in most cases, it copies the file)

daKmoR avatar Oct 24 '20 17:10 daKmoR

I was surprised there was no dest option. It works, but it is kind of a "cross your fingers and hope it goes to the right place" thing. Also, you could certainly see the use case of wanting to move things from dir-a to dir-b at the destination.

JoshMcCullough avatar Dec 30 '23 04:12 JoshMcCullough

My output.dir points to a js folder. How do I copy static files to its parent directory?

eight04 avatar Aug 22 '24 01:08 eight04