Comments (4)
However, I removed it when hook option was added. Currently, buildEnd
hook is used as a default one and it is executed before outputOptions
hook.
from rollup-plugin-copy.
I can add outputFolder
option back so you can set global folder once, but you'll still need to set it (duplicate). Don't know a way to make autodetection since outputOptions
can't be used with hook option.
What do you think?
from rollup-plugin-copy.
Hi everyone,
If I may, I think that something like a dest
global option could be great.
import {resolve} from "path";
const src = (...paths) => resolve("src", ...paths);
export default {
plugins: [
copy({
dest: resolve("dist"),
targets: [
src("index.html"),
src("service-worker.js"),
src("manifest.webmanifest"),
{
src: resolve("something", "else.json"),
dest: resolve("somewhere", "else")
}
]
})
]
}
This would have the advantage of being really concise and reduce the code written for copying multiple files to a similar location. Plus (but I'm really unsure about that) we could maybe use this plugin multiple times for multiple shared folders (while keeping the actual behavior).
import {resolve} from "path";
const src = (...paths) => resolve("src", ...paths);
const dist = (...paths) => resolve("dist", ...paths);
export default {
plugins: [
copy({
dest: dist("client"),
targets: [
src("foo"),
src("bar"),
src("baz")
]
}),
copy({
dest: dist("server"),
targets: [
src("foo"),
src("bar"),
src("baz")
]
})
]
}
As a workaround, I have found to be used this little function a lot in my Rollup projects. Here is the code snippet.
import {path} from "path";
const dist = (...paths) => resolve("path", "to", "dist", ...paths);
dist("client", "index.js"); // ./path/to/dist/client/index.js
dist("server", "main.js"); // ./path/to/dist/server/main.js
This also work independently on whether you are using GNU/Linux, Mac OS X or Windows since resolve
will join the strings with the correct delimiter for the current operating system using path.sep
.
I Hope it helps while a solution is found.
from rollup-plugin-copy.
@vladshcherbin Hey, I've worked around this allowing to specify function as dest
:
import RollupPluginCopy from "rollup-plugin-copy"
/** @param {import("rollup-plugin-copy").CopyOptions} options */
function copy(options) {
options.hook ??= "buildEnd"
return {
[options.hook](...args) {
options.targets = options.targets.map(({ dest, ...target }) => ({
...target,
dest: typeof dest === "function" ? dest(...args) : dest,
}))
const plugin = RollupPluginCopy(options)
return plugin[options.hook](...args)
},
}
}
export default {
plugins: [copy({
hook: "writeBundle",
targets: [{
src: "some/folder/files.*",
dest: cfg => cfg.dir,
})
}]
}
Feel free to borrow the idea ;)
from rollup-plugin-copy.
Related Issues (20)
- Promise support
- Negated patterns doesn't work correctly. HOT 1
- Has anyone been able to get this working in Sveltekit yet? HOT 3
- copy folder structure with flatten=false and ignore first levels HOT 3
- No error if target file does not exist
- The filter won't take effect when file transformed
- (copy plugin) Error: ENOENT: no such file or directory, chmod <filename> HOT 7
- copy occurs before generated bundle write when multi entry HOT 2
- unable to copy dot files from a directory ie. .htaccess HOT 1
- Symlinks HOT 2
- Move `@types/*` to `devDependencies`. HOT 3
- Create symlink instead of copy?
- Not working well in a Laravel project using Vite HOT 2
- The files in src cannot be obtained under the windows system HOT 3
- Rename does not let me alter the folder to which the file is written. HOT 1
- Please add your oss license text HOT 1
- `rename` option does not work in Rollup 4 HOT 1
- Compile typescript HOT 1
- Breaking dependency [email protected] HOT 3
- [Question] Is it possible to copy to a "hidden" folder?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rollup-plugin-copy.