web
web copied to clipboard
[rollup-plugin-copy] 'dest' option
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.)
What's your intention? To copy to a folder other than the rollup output directory?
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.
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.
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)
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.
My output.dir
points to a js
folder. How do I copy static files to its parent directory?