Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const onBundled = async (bundle: ParcelBundle): Promise => {
bundler.emit('pwaBuildStart');
const pkg = await getPkg(
bundle.entryAsset || bundle.childBundles.values().next().value.entryAsset
);
const opts = pkg.pwaManifest || pkg['pwa-manifest'];
// istanbul ignore next
if (typeof opts !== 'object') {
if (typeof opts === 'undefined')
throw 'No PWA Manifest options found in package.json.';
throw 'The PWA Manifest parameter in package.json must be an object containing the desired parameters.';
}
const generator = new PWAManifestGenerator(
opts,
{
baseURL: publicURL,
resolveDir: pkg.pkgdir
},
{
name: pkg.name,
desc: pkg.description
}
);
generator.on('*', (ev, ...args) => {
bundler.emit(`pwa${ev.slice(0, 1).toUpperCase() + ev.slice(1)}`, ...args);
if (ev.endsWith('Start')) {
logger.progress(args[0]);
}
});
this.cb = async (compilation, data) => {
const logger = compilation.getLogger(NAME);
try {
const gen = new PWAManifestGenerator(opts, {
baseURL: compilation.outputOptions.publicPath,
resolveDir: '.'
});
const compHooks = WebpackPluginPWAManifest.getHooks(compilation);
gen.on('*', (ev, ...args) => {
const hook = compHooks[ev];
if (hook.call) hook.call(...args);
else hook.promise(...args);
if (ev.endsWith('Start')) {
logger.group(args[0]);
}
});
if (!HtmlWebpackPlugin) {
logger.warn(
'html-webpack-plugin not installed, so HTML will not be injected.'
);