elegantapp / pwa-asset-generator

Automates PWA asset generation and image declaration. Automatically generates icon and splash screen images, favicons and mstile images. Updates manifest.json and index.html files with the generated images according to Web App Manifest specs and Apple Human Interface guidelines.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generate ONLY iOS or ONLY Android icons

husk-9 opened this issue · comments

  • My iOS icons should have a white background
  • My Android icon should have a transparent background

I'm currently using this script.

pwa.js

const { generateImages } = require('pwa-asset-generator');
const { rename } = require('fs').promises;

const pwaArgs = ['dist/logo.png', 'dist/images'];
const appleIcon = 'apple-icon-180.png';
const manifest = 'dist/manifest.json'; // Write to manifest.json
const index = ''; // Do not write to index.html
// Or you could read parameters from process.argv

(async () => {
  console.log('Generating Apple icon...');
  await generateImages(...pwaArgs, {
    background: '#227',
    iconOnly: true,
    log: false
  });
  console.log('Storing Apple icon...');
  await rename('dist/images/' + appleIcon, 'dist/' + appleIcon);
  console.log('Generating transparent icons...');
  await generateImages(...pwaArgs, {
    ...(manifest && { manifest }),
    ...(index && {index}),
    opaque: false,
    favicon: true,
    mstile: true,
    log: false
  });
  // TODO: Reprettify index.html
  console.log('Replacing Apple icon...');
  await rename('dist/' + appleIcon, 'dist/images/' + appleIcon);
  console.log('Generating Apple splash screens...');
  await generateImages(...pwaArgs, {
    background: '#227',
    splashOnly: true,
    log: false
  });
  console.log('Completed.');
})();

package.json

{
  "scripts": {
    "generate-pwa-asset": "node pwa.js"
  }
}