npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webmanifest-loader

v0.3.0

Published

Help deal with Web App Manifest files.

Downloads

1,207

Readme

webmanifest loader for webpack Version Build Status

Parses your web app manifest, loading the necessary files from your icons and screenshots sections.

It also treats your web app manifest as a lodash template, so you can interpolate variables or add any other logic you need.

Installation

$ npm install --save webmanifest-loader

Usage

Documentation: Using loaders

Say you are using html-webpack-plugin, and you want to add a web app manifest. Your HTML template template.ejs could look like this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title><%= htmlWebpackPlugin.options.title %></title>
    <link rel="manifest" href="<%= require('./manifest.webmanifest') %>" />
  </head>
  <body>
    <div id="root"></div>
  </body>
</html>

Your manifest.webmanifest file could look like this:

{
  "name": "<%= name %>",
  "short_name": "<%= shortName %>",
  "description": "<%= description %>",
  "start_url": ".",
  "display": "standalone",
  "icons": [
    {
      "src": "./icon_144x144.png",
      "sizes": "144x144",
      "type": "image/png"
    },
    {
      "src": "./icon_192x192.png",
      "sizes": "192x192",
      "type": "image/png"
    }
  ],
  "screenshots": [
    {
      "src": "./screenshot.jpg",
      "sizes": "640x480",
      "type": "image/jpeg"
    },
    {
      "src": "./[email protected]",
      "sizes": "1280x920",
      "type": "image/jpeg"
    }
  ]
}

And your webpack.config.js file would glue everything together:

var HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  entry: {
    app: './index.js'
  },

  output: {
    path: './dist/',
    filename: '[name].js'
  },

  module: {
    rules: [
      {
        test: /\.webmanifest$/,
        include: /assets\//,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: '[name].[ext]'
            }
          },
          {
            loader: 'webmanifest-loader',
            options: {
              name: 'Foobar',
              shortName: 'Foobar',
              description: 'Just an example.'
            }
          }
        ]
      },
      {
        test: /\.(jpg|png)$/,
        include: /assets\//,
        use: {
          loader: 'file-loader',
          options: {
            name: '[name].[ext]'
          }
        }
      }
    ]
  },

  plugins: [
    new HtmlPlugin({
      title: 'Foobar',
      template: './assets/template.ejs'
    })
  ]
}

Running webpack would produce all the necessary files as expected:

$ npm run build

> [email protected] build /Users/daniel/Code/webmanifest-loader/example
> webpack

Hash: 6988311fefbc63ba7777
Version: webpack 4.1.1
Time: 390ms
Built at: 2018-3-13 20:23:05
               Asset       Size  Chunks             Chunk Names
manifest.webmanifest  586 bytes          [emitted]
   [email protected]    0 bytes          [emitted]
      screenshot.jpg    0 bytes          [emitted]
    icon_192x192.png    0 bytes          [emitted]
    icon_144x144.png    0 bytes          [emitted]
              app.js  571 bytes       0  [emitted]  app
          index.html  354 bytes          [emitted]
Entrypoint app = app.js
   [0] ./index.js 22 bytes {0} [built]
Child html-webpack-plugin for "index.html":
                   Asset       Size  Chunks             Chunk Names
    manifest.webmanifest  586 bytes          [emitted]
       [email protected]    0 bytes          [emitted]
          screenshot.jpg    0 bytes          [emitted]
        icon_192x192.png    0 bytes          [emitted]
        icon_144x144.png    0 bytes          [emitted]
     + 1 hidden asset
    Entrypoint undefined = index.html
       [0] ./assets/manifest.webmanifest 66 bytes {0} [built]
       [1] (webpack)/buildin/module.js 519 bytes {0} [built]
       [2] (webpack)/buildin/global.js 509 bytes {0} [built]
       [4] ./node_modules/html-webpack-plugin/lib/loader.js!./assets/template.ejs 779 bytes {0} [built]
       [5] ./assets/[email protected] 63 bytes [built]
       [6] ./assets/screenshot.jpg 60 bytes [built]
       [7] ./assets/icon_192x192.png 62 bytes [built]
       [8] ./assets/icon_144x144.png 62 bytes [built]
        + 1 hidden module

Go to the example folder and try it yourself:

$ cd example
$ npm install
$ npm run build

Meta

Contributors

License

Copyright (c) 2017 Daniel Perez Alvarez (unindented.org). This is free software, and may be redistributed under the terms specified in the LICENSE file.