Offline Bundler Plugin

1.0.3 · active · verified Tue Apr 21

The `offline-bundler-plugin` is a JavaScript/TypeScript utility designed to prepare web applications for offline access. It automates the process of compressing static assets (including JavaScript, CSS, images, and HTML) into a single zip archive and simultaneously generates a resource mapping JSON file. This manifest maps remote URLs of assets to their corresponding local paths within the generated bundle, facilitating efficient offline caching and retrieval. Currently at version 1.0.3, the plugin boasts compatibility with both Webpack and Vite (including UniApp environments), offering broad utility across modern frontend build setups. Its key differentiator lies in its dual-bundler support and its specialized focus on creating structured resource manifests, which goes beyond simple asset compression to enable robust offline-first strategies.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure `offline-bundler-plugin` for both Webpack and Vite projects, highlighting the distinct import and instantiation patterns for each bundler. It shows basic configuration options for bundling static assets into a zip with a resource mapping JSON.

// For Webpack: webpack.config.js (or similar, requiring commonjs)
const OfflinePackagePluginWebpack = require('offline-bundler-plugin');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: 'production',
  entry: './src/index.js',
  output: {
    filename: '[name].[contenthash].js',
    path: path.resolve(__dirname, 'dist-webpack'),
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html',
      filename: 'index.html',
    }),
    new OfflinePackagePluginWebpack({
      packageNameKey: 'packageId',
      packageNameValue: 'my-app-webpack',
      version: 1,
      baseUrl: 'http://localhost:8080/', // Replace with your actual deployment base URL
      fileTypes: ['html', 'js', 'css', 'png'],
      folderName: 'offline-bundle-webpack',
    }),
  ],
};

// For Vite: vite.config.ts (or similar, using ESM)
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react'; // Example framework plugin
import OfflinePackagePluginVite from 'offline-bundler-plugin/vite';

export default defineConfig({
  plugins: [
    react(),
    OfflinePackagePluginVite({
      packageNameKey: 'packageId',
      packageNameValue: 'my-app-vite',
      version: 1,
      baseUrl: 'http://localhost:3000/', // Replace with your actual deployment base URL
      fileTypes: ['html', 'js', 'css', 'png'],
      folderName: 'offline-bundle-vite',
    }),
  ],
  build: {
    outDir: 'dist-vite',
  },
});

view raw JSON →