plugins_release_pwa.js

// @ts-check
/**
 * @file plugin/pwa.js
 * @version 0.0.1
 * @copyright 2025 SPMHome
 * @author Scott Meesseman @spmeesseman
 *//** */

const WpwPlugin = require("../base");
// const {GenerateSW} = require("workbox-webpack-plugin");


/**
 * @augments WpwPlugin
 */
class WpwPwaPlugin extends WpwPlugin
{
	/**
	 * @param {WpwPluginOptions} options Plugin options to be applied
	 */
	constructor(options)
	{
		super(options);
        this.buildOptions = /** @type {WpwBuildOptionsConfig<"pwa">} */(this.buildOptions);
	}


	/**
     * @override
     */
	static create = WpwPwaPlugin.wrap.bind(this);


    /**
     * @override
     * @returns {WpwPluginTapOptions<any, any, boolean> | undefined}
     */
    onApply()
    {
		// if (this.buildOptions.abc.enabled))
		// {
		// 	const hooks = {
		// 		abc: {
		// 			hook: "compilation",
		// 			stage: "ADDITIONAL",
		// 			statsProperty: "copied",
		// 			hookCompilation: "processAssets",
		// 			callback: this.emitEntryModulesNoHash.bind(this)
		// 		},
		// 		def: {
		// 			hook: "compilation",
		// 			stage: "DEV_TOOLING",
		// 			hookCompilation: "processAssets",
		// 			callback: this.sourcemap.bind(this)
		// 		}
		// 	};
		// 	return /** @type {WpwPluginTapOptions} */(hooks);
		// }
		return {};
    }

	// /**
	//  * @override
    //  * @param {WebpackCompiler} compiler
    //  * @param {boolean} [applyFirst]
	//  * @returns {WebpackPluginInstance | undefined}
	//  */
	// getVendorPlugin(compiler, applyFirst)
	// {
	// 	if (this.buildOptions.enabled)
	// 	{
	// 		return new GenerateSW(
	// 		{
	// 			exclude: [ /\.mp4|\.mov/, ".mp3" ],
	// 			maximumFileSizeToCacheInBytes: 1280000,
	// 			navigateFallback: "/index.html",
	// 			runtimeCaching: [
	// 			{
	// 				urlPattern: ({request, url}) => url.pathname.includes("/api/"),
	// 				handler: "StaleWhileRevalidate",
	// 				options: {
	// 					cacheName: "wpw-cache-api-12-31-24",
	// 					expiration: {
	// 						maxEntries: 25
	// 					}
	// 				}
	// 			},
	// 			{
	// 				urlPattern: new RegExp(/\/api\/v1\//),
	// 				handler: "CacheFirst",
	// 				options: {
	// 					cacheName: "wpw-cache-list-12-31-24",
	// 					plugins: []
	// 				}
	// 			}],
	// 			skipWaiting: true
	// 		});
	// 	}
	// };
}


module.exports = WpwPwaPlugin.create;