vite-pwa / vite-plugin-pwa

Zero-config PWA for Vite
https://vite-pwa-org.netlify.app/
MIT License
3.22k stars 211 forks source link

Update from 0.20.0 to 0.20.1 makes assets disappear during build #738

Closed AC-CHN closed 3 months ago

AC-CHN commented 3 months ago

When updating from 0.20.0 to 0.20.1, the phenomenon occurs that assets which were still included in version 0.20.0 through the config with includeassets disappear with 0.20.1.

The entry includeAssets: ['favicon.ico', 'robots.txt', '.png', '.json', '../src/assets/images/*/'], in vitePWAOptions: Partial loads assets from the specified folder '../src/assets/images/*/' into the manifest in version 0.20.0.

in version 0.20.1 not anymore.

I think this is because the npm package for the globs has been swapped.

0.20.0 assets.ts import fg from 'fast-glob' let assets = await fg( globs, { cwd: publicDir,

    onlyFiles: true,
    unique: true,
  },
)

0.20.1 assets.ts import { glob } from 'tinyglobby' let assets = await glob({ patterns: globs,

  cwd: publicDir,
  expandDirectories: false,
  onlyFiles: true,
})
userquin commented 3 months ago

Any asset inside assets folder not referenced in your app will be missing in the dist folder (should be used via src img or using them via static/dynamic import), Vite will not copy those assets if not referenced. Maybe latest Vite versions change the behavior, can you provide a minimal reproduction?

includeAssets is about entries in public folder, Vite will copy those assets on final build step, the pwa plugin will include the corresponding entries in the sw precaching manifest since Vite copies the public dir at the end of the build (the pwa plugin will not copy any asset to the dist folder from your src folder).

AC-CHN commented 3 months ago

@userquin You can reproduce it via https://github.com/AC-CHN/VitePWA_IssueDemo.

It works with version 0.20.0. Not with 0.20.1.

The aim is to have the images from the assets/images folder as precache in the manifest so that they do not have to be loaded manually but are directly available because they are the content of a dropdown as an icon.

0 20 0 0 20 1

userquin commented 3 months ago

https://github.com/vite-pwa/vite-plugin-pwa/issues/737#issuecomment-2278094921

(use injectManifest.globPatterns)

AC-CHN commented 3 months ago

Nice :) Thank you !