The `parcel-plugin-sw-asset-urls` (version 0.1.2) is a plugin specifically designed for `parcel-bundler` (Parcel v1.x) that addresses a common issue in Progressive Web App (PWA) development. Parcel automatically generates static assets with hashed filenames for effective browser cache busting. However, in Parcel v1, it does not inherently update the `sw.js` (service worker) file with these newly hashed URLs, leading to broken asset paths in the service worker's cache manifest. This plugin integrates into the Parcel v1 build process to replace the original, unhashed asset filenames within the generated service worker script with their corresponding hashed versions in the `dist` directory. This ensures the service worker correctly identifies and caches the fingerprinted assets. The package is currently at an early version (0.1.2) and its development is tied to Parcel v1, making it incompatible with Parcel v2, which has a different plugin architecture and often handles such issues internally or with updated strategies.
npm install parcel-plugin-sw-asset-urlsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a minimal Parcel v1 project with the plugin. It shows how the plugin automatically replaces unhashed asset URLs in `service-worker.js` with their fingerprinted versions after a Parcel build, which is crucial for correct PWA caching.
For Parcel v2, consult the official Parcel documentation for handling service workers and asset hashing. Parcel v2 may provide native solutions or require different plugin approaches.
Consider alternatives or be prepared to fork and maintain the code yourself if you need this functionality with Parcel v1. For new projects, use Parcel v2, which is actively maintained.
Migrate your project to Parcel v2. This will involve updating dependencies (e.g., `parcel-bundler` to `parcel`), adjusting project configuration, and potentially finding new solutions for functionalities previously provided by Parcel v1-specific plugins like this one.
Ensure `parcel-bundler` (specifically version 1.x) is installed as a development dependency: `npm install parcel-bundler@^1.11.0 -D` or `yarn add parcel-bundler@^1.11.0 -D`. Verify your `package.json` to confirm the correct Parcel version.
Verify that your project is configured to use `parcel-bundler` (Parcel v1). If you intend to use Parcel v2, you will need to find a Parcel v2-compatible solution for updating service worker asset URLs, as this plugin is not compatible.