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.
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.
Hi,
We're running into an issue when using
rollup-plugin-cpy
withrollup-plugin-workbox
. The workbox plugin will run at thewriteBundle
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:
Result:
Only 1 URL is precached, because workbox finishes before the files are copied. I'd expect 2 URLS to be precached;
dist/index.js
anddist/img.png
.As I understand correctly from reading the source code of
rollup-plugin-cpy
, nothing inrollup-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 thewriteBundle
hook starts, because (from my understanding) rollup will await thebuildStart
hooks before moving on.This would mean a small code change on line 44:
Would love to hear your thoughts about this, i'd be happy to make a PR 😊