Giter Site home page Giter Site logo

jcalixte / vue-pwa-asset-generator Goto Github PK

View Code? Open in Web Editor NEW
172.0 3.0 6.0 3.15 MB

PWA asset generator perfect with VueJS framework (but useful for all PWA!)

JavaScript 100.00%
pwa icon manifest vuejs ios android pwa-assets icons progressive-web-app progressive-web-apps

vue-pwa-asset-generator's Introduction

Vue PWA asset generator

npm npm

TLDR:

npx vue-pwa-asset-generator -a {512x512_png_source | svg_source} [-o {output_folder} [-b {fallback background color}]]

This package creates for you all the default assets used in a VueJS app with PWA plugin as well as a manifest JSON with the icons attribute set.

demo

Installation

You can use npx as shown above or you can install it globally:

npm install --global vue-pwa-asset-generator

or

yarn global add vue-pwa-asset-generator

or

pnpm global add vue-pwa-asset-generator

Usage

VueJS PWA asset generator has a vue-asset-generate command with two parameters:

  • -a: input asset, it can be an SVG file or a PNG file (the largest image is a 512x512 png image).
  • -o: output folder (created if it does not exist). This parameter is optional, by default, vue-pwa-asset-generator will assume the command is run in a VueJS project. Therefor the manifest.json and favicon.ico are in public folder, the rest ies in public/img/icons folder.
  • -b: fallback background color for the ico image.
  • --no-manifest: option to not generate manifest.json file

Examples

  • vue-asset-generate -a logo.png -o img
  • vue-asset-generate -a logo.svg
  • vue-asset-generate -a logo.svg -o img
  • vue-asset-generate -a logo.svg -o img -b 182C61
  • vue-asset-generate -a logo.svg -o img -b "#9AECDB"

"Hey, I'm using the Vue plugin for pwa. Where do I put my manifest json?"

You can configure your PWA with the vue.config.js file.

Here an example of how you can merge the created manifest.json and your configuration file:

module.exports = {
  // ... other configurations
  pwa: {
    themeColor: "#130f40",
    msTileColor: "#130f40",
    name: "My app",
    manifestOptions: {
      icons: [
        {
          src: "./img/icons/android-chrome-192x192.png",
          sizes: "192x192",
          type: "image/png",
        },
        {
          src: "./img/icons/android-chrome-512x512.png",
          sizes: "512x512",
          type: "image/png",
        },
        {
          src: "./img/icons/android-chrome-maskable-192x192.png",
          sizes: "192x192",
          type: "image/png",
          purpose: "maskable",
        },
        {
          src: "./img/icons/android-chrome-maskable-512x512.png",
          sizes: "512x512",
          type: "image/png",
          purpose: "maskable",
        },
        {
          src: "./img/icons/apple-touch-icon-60x60.png",
          sizes: "60x60",
          type: "image/png",
        },
        {
          src: "./img/icons/apple-touch-icon-76x76.png",
          sizes: "76x76",
          type: "image/png",
        },
        {
          src: "./img/icons/apple-touch-icon-120x120.png",
          sizes: "120x120",
          type: "image/png",
        },
        {
          src: "./img/icons/apple-touch-icon-152x152.png",
          sizes: "152x152",
          type: "image/png",
        },
        {
          src: "./img/icons/apple-touch-icon-180x180.png",
          sizes: "180x180",
          type: "image/png",
        },
        {
          src: "./img/icons/apple-touch-icon.png",
          sizes: "180x180",
          type: "image/png",
        },
        {
          src: "./img/icons/favicon-16x16.png",
          sizes: "16x16",
          type: "image/png",
        },
        {
          src: "./img/icons/favicon-32x32.png",
          sizes: "32x32",
          type: "image/png",
        },
        {
          src: "./img/icons/msapplication-icon-144x144.png",
          sizes: "144x144",
          type: "image/png",
        },
        {
          src: "./img/icons/mstile-150x150.png",
          sizes: "150x150",
          type: "image/png",
        },
      ],
    },
  },
};

⚠️

When generating assets from a png file, the generator creates a black and white svg for the safari-pinned-tab.svg icon, some manual modifications may be necessary.

I hope this will be useful as it is for me! ♥

vue-pwa-asset-generator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-pwa-asset-generator's Issues

android-chrome-512x512.png is deleted when the -b flag is not used

vue-asset-generate -a logo.png -o test

gives all files except android-chrome-512x512.png (it is created but instantly deleted)

vue-asset-generate -a logo.png -o test -b "#3a3a3a"

gives all files (correct)

Something wrong with generateFavicon under script/modules/favicon.js when called from script/index.js I think

if (background)

on line 17 must resolve to true to prevent android-chrome-512x512.png from being deleted

Unable to install npm package

Unable to install this package Linux Mint 19.3

master@master:~/WebProjects/vue-portfolio$ sudo npm install --global vue-pwa-asset-generator
loadDep:yargs → get       ▄ ╢████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
loadDep:yargs → etag      ▄ ╢████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
loadDep:tunnel-agent → ge ▐ ╢███████████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
loadDep:tunnel-agent → 30 ▐ ╢███████████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
loadDep:readable-stream → ▀ ╢██████████████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
WARN engine [email protected]: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
loadDep:mimic-response →  ▀ ╢██████████████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
WARN engine [email protected]: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
/usr/local/bin/vue-asset-generate -> /usr/local/lib/node_modules/vue-pwa-asset-generator/script/index.js

> [email protected] install /usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)

info sharp Using cached /home/master/.npm/_libvips/libvips-8.9.1-linux-x64.tar.gz
prebuild-install WARN This package does not support N-API version undefined 
prebuild-install WARN install EACCES: permission denied, access '/home/master/.npm'
make: Entering directory '/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/sharp/build'
  CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
  AR(target) Release/obj.target/../node-addon-api/nothing.a
  COPY Release/nothing.a
  TOUCH Release/obj.target/libvips-cpp.stamp
  CXX(target) Release/obj.target/sharp/src/common.o
In file included from ../src/common.cc:22:0:
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi.h:1939:33: error: ‘napi_callback_scope’ has not been declared
     CallbackScope(napi_env env, napi_callback_scope scope);
                                 ^~~~~~~~~~~~~~~~~~~
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi.h:1946:14: error: expected type-specifier before ‘napi_callback_scope’
     operator napi_callback_scope() const;
              ^~~~~~~~~~~~~~~~~~~
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi.h:1952:5: error: ‘napi_callback_scope’ does not name a type; did you mean ‘napi_callback_info’?
     napi_callback_scope _scope;
     ^~~~~~~~~~~~~~~~~~~
     napi_callback_info
In file included from /usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi.h:2426:0,
                 from ../src/common.cc:22:
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h:4009:17: error: ‘napi_callback_scope’ has not been declared
   napi_env env, napi_callback_scope scope) : _env(env), _scope(scope) {
                 ^~~~~~~~~~~~~~~~~~~
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h: In constructor ‘Napi::CallbackScope::CallbackScope(napi_env, int)’:
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h:4009:57: error: class ‘Napi::CallbackScope’ does not have any field named ‘_scope’
   napi_env env, napi_callback_scope scope) : _env(env), _scope(scope) {
                                                         ^~~~~~
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h: In constructor ‘Napi::CallbackScope::CallbackScope(napi_env, napi_async_context)’:
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h:4015:41: error: ‘_scope’ was not declared in this scope
       _env, Object::New(env), context, &_scope);
                                         ^~~~~~
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h:4015:41: note: suggested alternative: ‘bcopy’
       _env, Object::New(env), context, &_scope);
                                         ^~~~~~
                                         bcopy
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h:4014:24: error: ‘napi_open_callback_scope’ was not declared in this scope
   napi_status status = napi_open_callback_scope(
                        ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h:4014:24: note: suggested alternative: ‘napi_open_handle_scope’
   napi_status status = napi_open_callback_scope(
                        ^~~~~~~~~~~~~~~~~~~~~~~~
                        napi_open_handle_scope
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h: In destructor ‘virtual Napi::CallbackScope::~CallbackScope()’:
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h:4020:56: error: ‘_scope’ was not declared in this scope
   napi_status status = napi_close_callback_scope(_env, _scope);
                                                        ^~~~~~
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h:4020:56: note: suggested alternative: ‘bcopy’
   napi_status status = napi_close_callback_scope(_env, _scope);
                                                        ^~~~~~
                                                        bcopy
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h:4020:24: error: ‘napi_close_callback_scope’ was not declared in this scope
   napi_status status = napi_close_callback_scope(_env, _scope);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h:4020:24: note: suggested alternative: ‘napi_close_handle_scope’
   napi_status status = napi_close_callback_scope(_env, _scope);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~
                        napi_close_handle_scope
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h: At global scope:
/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/node-addon-api/napi-inl.h:4026:32: error: expected type-specifier before ‘napi_callback_scope’
 inline CallbackScope::operator napi_callback_scope() const {
                                ^~~~~~~~~~~~~~~~~~~
cc1plus: warning: unrecognized command line option ‘-Wno-cast-function-type’
sharp.target.mk:123: recipe for target 'Release/obj.target/sharp/src/common.o' failed
make: *** [Release/obj.target/sharp/src/common.o] Error 1
make: Leaving directory '/usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/sharp/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Linux 5.4.0-37-generic
gyp ERR! command "/usr/bin/node" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/vue-pwa-asset-generator/node_modules/sharp
gyp ERR! node -v v8.10.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
/usr/local/lib
└── (empty)

npm ERR! Linux 5.4.0-37-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "--global" "vue-pwa-asset-generator"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `(node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script '(node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the sharp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs sharp
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls sharp
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/master/WebProjects/vue-portfolio/npm-debug.log
npm ERR! code 1
master@master:~/WebProjects/vue-portfolio$ 

favicon.svg

Is your feature request related to a problem? Please describe.
It seems like the new Vue PWA plugin requires a favicon.svg asset now... Could you provide it through your tool?

Describe the solution you'd like
Add a favicon.svg asset (from a icon.svg base asset maybe?)

Describe alternatives you've considered
Manual action...

Additional context
Using "@vue/cli-plugin-pwa": "~5.0.0",

Security issues due to outdated dependencies

The tool is flagged by npm audit due to outdated dependencies.
The suggested resolution is to downgrade the package to 0.1.2, which is undesirable.

I believe that the dependencies should be correctly upgraded.

Check File Exists Before Proceeding

i saw the code and its not checking if the image file exists, user can easily typo the name and he will see lot of red errors.

A polite message should be returned letting him know that no file found

Generate android-chrome-maskable PNGs and safari-pinned-tab SVG

Is your feature request related to a problem? Please describe.
Three files included with the Vue CLI setup of a PWA are not generated by vue-pwa-asset-generator:

  • android-chrome-maskable-192x192.png
  • android-chrome-maskable-512x512.png
  • safari-pinned-tab.svg

Describe the solution you'd like
I would like these three files to be generated as well.

Describe alternatives you've considered
Could manually make them but that seems kind of silly, considering the purpose of this project. 🤷‍♂️

Additional context
Generated icons via this command, but the output lacked the three files mentioned above:

npx vue-pwa-asset-generator -a Desktop/icon.png -o icons

Support SVG for Intake Asset

Is your feature request related to a problem? Please describe.

My base icon is an SVG. To use this tool, I have to do the following.

  • Convert the SVG (icon.svg) to a PNG (icon-512x512.png)
  • Run vue-asset-generate -a ./icon-512x512.png -o ./icons/
  • Replace the generated SVG with the original: cp icon.svg ./icons/safari-pinned-tab.svg

Describe the solution you'd like

Ideally, this feature would allow me to use an SVG as my intake asset. E.g.

vue-asset-generate -a ./icon.svg -o ./icons/

It would also use the intake SVG for the generated safari-pinned-tab.svg asset.

Describe alternatives you've considered

I am doing this manually at the moment (npm scripts). This package is wonderful, and I feel like it makes sense to support multiple intake asset types.

bg image

First,
thanks for that package.
I was using my python script in the past, this one is way more comfortable.

The idea:

Default background is white, for targets that doesn't support transparency.

I'll like to have another command line option ( -bg ?)
to provide a secondary image.

That image, in my suggestion, should melt with the primary image, to compose the final image.

Ciaooo!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.