sw 0.0.5 copy "sw: ^0.0.5" to clipboard
sw: ^0.0.5 copied to clipboard

A command-line tool to generate service worker files for web applications. It simplifies the process of creating service workers.

Service Worker Generator #

Checkout Pub Package License: MIT Dart Flutter

A powerful command-line tool for automatically generating Service Worker files for web applications. Specifically designed for Dart and Flutter Web applications, it simplifies the process of creating efficient service workers with intelligent resource caching.

๐Ÿš€ Features #

  • โœ… Automatic File Scanning โ€” Analyzes build directory and creates resource map with MD5 hashes
  • โœ… Smart Caching Strategy โ€” Implements cache-first with network fallback and runtime caching
  • โœ… Version Management โ€” Handles cache versioning for safe deployments and updates
  • โœ… Flexible File Filtering โ€” Include/exclude files using powerful glob patterns
  • โœ… Flutter Web Optimized โ€” Special support for Flutter web applications and assets
  • โœ… Cross-Platform โ€” Works seamlessly on Windows, macOS, and Linux
  • โœ… Customizable Cache Names โ€” Configure cache prefixes and versions
  • โœ… Integrity Validation โ€” MD5 hashing for file integrity verification
  • โœ… Offline Support โ€” Ensures your app works without internet connection
  • โœ… PWA Ready โ€” Perfect for Progressive Web Applications

๐Ÿ“ฆ Installation #

Global Installation #

dart pub global activate sw

๐Ÿ›  Usage #

Basic Usage #

dart run sw:generate --help

Advanced Usage #

# Custom input directory and output file
dart run sw:generate --input build/web --output flutter_service_worker.js

# Custom cache prefix and version
dart run sw:generate --prefix my-app --version 1.2.3

# Filter files with glob patterns
dart run sw:generate \
    --glob="**.{html,js,wasm,json}; assets/**; canvaskit/**; icons/**"
    --no-glob="flutter_service_worker.js; **/*.map; assets/NOTICES"

# Include comments in generated file
dart run sw:generate --comments

๐Ÿ“‹ Command Line Options #

Option Short Description Default
--help -h Show help information -
--input -i Path to build directory containing index.html build/web
--output -o Output service worker filename sw.js
--prefix -p Cache name prefix app-cache
--version -v Cache version current timestamp
--glob -g Glob patterns to include files **
--no-glob -e Glob patterns to exclude files -
--comments -c Include comments in generated file false

๐Ÿ“ Usage Examples #

# 1. Install dependencies
flutter pub get

# 2. Activate the service worker generator
dart pub global activate sw

# 3. (Optional) Run code generation
dart run build_runner build --delete-conflicting-outputs --release

# 4. Build Flutter project
flutter build web --release --no-tree-shake-icons --no-web-resources-cdn --base-href=/ -o build/web

# 5. Generate service worker
dart run sw:generate --input=build/web \
    --output=flutter_service_worker.js \
    --prefix=flutter-app \
    --glob="**.{html,js,wasm,json}; assets/**; canvaskit/**; icons/**" \
    --no-glob="flutter_service_worker.js; **/*.map; assets/NOTICES" \
    --comments

๐Ÿ“– Generated Service Worker Structure #

The generated service worker includes:

  • ๐Ÿ—„๏ธ Resource Caching โ€” All specified files are cached during installation
  • โšก Cache-First Strategy โ€” Prioritizes cache over network for better performance
  • ๐Ÿ”„ Cache Versioning โ€” Automatic cache updates when version changes
  • ๐Ÿงน Smart Cleanup โ€” Removes old cache versions automatically
  • ๐Ÿ“ฑ Runtime Caching โ€” Dynamic caching of new resources during runtime
  • ๐Ÿ” Integrity Checks โ€” MD5 hash validation for cached resources
  • โฑ๏ธ TTL Support โ€” Time-based cache expiration
  • ๐Ÿ“Š Size Limits โ€” Configurable cache size limits

๐Ÿค Contributing #

We welcome contributions to this project! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes and add tests
  4. Ensure all tests pass (dart test)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Create a Pull Request

To use this package from local path, you can clone the repository and run:

dart pub global activate --source path .

๐Ÿ“ License #

This project is licensed under the MIT License. See the LICENSE file for details.

5
likes
150
points
134
downloads

Publisher

verified publisherplugfox.dev

Weekly Downloads

A command-line tool to generate service worker files for web applications. It simplifies the process of creating service workers.

Repository (GitHub)
View/report issues
Contributing

Topics

#service-worker #generator #cli #web #flutter

Documentation

API reference

License

MIT (license)

Dependencies

args, crypto, glob, path

More

Packages that depend on sw