paulmelnikow / rollup-plugin-cpy Goto Github PK
View Code? Open in Web Editor NEWRollup plugin to easily copy files and folders
License: MIT License
Rollup plugin to easily copy files and folders
License: MIT License
Similar to: https://github.com/vladshcherbin/rollup-plugin-copy#hook
The current writeBundle
hook is good for when this plugin is used as an output plugin, but it causes the plugin to copy the files once per output when used in the options's plugins.
buildEnd
is maybe a better default to avoid this issue.
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
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
.
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 ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.