PWA Assets Generator API
From v0.2.0, @vite-pwa/assets-generator is shipped with a CLI, an API (low-level api): refer to API for more details.
The API can be found in the api folder.
Installation
This package is shipped with the @vite-pwa/assets-generator package:
pnpm add -D @vite-pwa/assets-generatoryarn add -D @vite-pwa/assets-generatornpm install -D @vite-pwa/assets-generatorAPI
From version v0.2.0, @vite-pwa/assets-generator exposes the following packages:
@vite-pwa/assets-generator/api: low-level functions api.- new
@vite-pwa/assets-generator/api/instructions:instructionsfunction to collect the icon assets instructions. - new
@vite-pwa/assets-generator/api/generate-assets:generateAssetsfunction to generate icon assets from an instruction. - new
@vite-pwa/assets-generator/api/generate-html-markup:generateHtmlMarkupfunction to generate all html head links from an instruction. - new
@vite-pwa/assets-generator/api/generate-manifest-icons-entry:generateManifestIconsEntryfunction to generate the PWA web manifest icons' entry.
The API can be found in the api folder and the JSDOCS documentation.
If you need to generate the PWA assets from your own code, you can use the instructions, generateHtmlMarkup, generateAssets and generateManifestIconsEntry functions:
- instructions: collect the icon assets instructions, provides function helpers to generate each icon asset as a
Bufferand html head links withstringandobjectnotation. - generateAssets: once you collect the icon assets instructions, you can use this function to save all the icon assets to the file system.
- generateHtmlMarkup: once you collect the icon assets instructions, you can use this function to generate all the html head markup for the icon assets.
- generateManifestIconsEntry function to generate the PWA web manifest icons' entry.
INFO
We're working to expose the new api in vite-plugin-pwa plugin and the integrations.
v0.1.0 deprecated
As mentioned previously, the API is low-level, it means that you have to handle the default values yourself: you can check the default values in the defaults.ts module.
The CLI has been rebuilt on top of the API, you can check the CLI documentation for more details about the default values.