Need help with webapp-webpack-plugin?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

brunocodutra
125 Stars 16 Forks MIT License 247 Commits 18 Opened issues

Description

[DEPRECATED] use favicons-webpack-plugin instead

Services available

!
?

Need anything else?

Contributors list

# 108,750
templat...
C++
cpp11
single-...
167 commits
# 198
nextjs
postman...
graphql...
angular...
32 commits
# 5,543
JavaScr...
html-we...
Webpack
Less
17 commits
# 52,341
TypeScr...
cyclejs
React
repl
1 commit
# 58,088
React
feather...
React N...
Haxe
1 commit
# 393,986
HTML
Webpack
html-we...
CSS
1 commit
# 75,029
TeX
crop-im...
Git
gerrit
1 commit
# 115,297
Markdow...
React
HTML
Webpack
1 commit
# 65,808
Webpack
Sass
helmet
standal...
1 commit
# 86,232
webpack...
CSS
HTML
html-we...
1 commit
# 164,923
PHP
Webpack
html-we...
Shell
1 commit
# 434,196
JavaScr...
HTML
Webpack
html-we...
1 commit
# 548,739
HTML
Webpack
html-we...
favicon
1 commit
# 86,068
craftcm...
craft-p...
webpack...
yii2
1 commit
# 91,955
seleniu...
Webpack
html-we...
design-...
1 commit
# 189,824
HTML
CSS
Webpack
webperf
1 commit
# 543,200
HTML
Webpack
html-we...
favicon
1 commit
# 12,293
JavaScr...
vue-rou...
Nuxt.js
nuxt-mo...
1 commit
# 693,037
HTML
Webpack
html-we...
favicon
1 commit

npm version Coverage Status Build Status Build status Greenkeeper badge Dependency Status

Leverages on favicons to automatically generate your progressive web app for you.

Originally forked from jantimon/favicons-webpack-plugin
What's new?

Installation

Install the plugin with npm:

shell
$ npm install --save-dev webapp-webpack-plugin

Basic Usage

Add the plugin to your webpack config as follows:

const WebappWebpackPlugin = require('webapp-webpack-plugin')

...

plugins: [ new WebappWebpackPlugin('/path/to/logo.png') // svg works too! ]

The default configuration will automatically generate webapp manifest files along with 44 different icon formats as appropriate for iOS devices, Android devices, Windows Phone and various desktop browsers out of your single

logo.png
.

Tip: You might want to fine tune what vendors to support.

A Note on Path Resolution

Under the hood, Webpack resolves the path to logo according to the following rules:

  • If

    /path/to/logo
    is absolute, there is nothing to resolve and the path specified is used as is.
  • If

    ./path/to/logo
    is relative, it's resolved with respect to Webpack's
    context
    , which defaults to
    process.cwd()
    .
  • If

    path/to/logo
    is neither explicitly relative nor absolute, Webpack attempts to resolve it according to
    resolve.modules
    , which defaults to
    modules: ["node_modules"]
    .

HTML Injection

In combination with html-webpack-plugin it will also inject the necessary html for you:

Note:

html-webpack-plugin
must come before
webapp-webpack-plugin
in the plugins array.

































https://github.com/brunocodutra/webapp-webpack-plugin/blob/master/test/fixtures/expected/html

Advanced Usage

plugins: [
  new WebappWebpackPlugin({
    // Your source logo (required)
    logo: '/path/to/logo.png',
    // Enable caching and optionally specify the path to store cached data
    // Note: disabling caching may increase build times considerably
    cache: true,
    // Override the publicPath option usually read from webpack configuration
    publicPath: '/static',
    // The directory to output the assets relative to the webpack output dir.
    // Relative string paths are allowed here ie '../public/static'. If this
    // option is not set, `prefix` is used.
    outputPath: '/public/static',
    // Prefix path for generated assets
    prefix: 'assets/',
    // Inject html links/metadata (requires html-webpack-plugin).
    // This option accepts arguments of different types:
    //  * boolean
    //    `false`: disables injection
    //    `true`: enables injection if that is not disabled in html-webpack-plugin
    //  * string
    //    `'force'`: enables injection even if that is disabled in html-webpack-plugin
    //  * function
    //    any predicate that takes an instance of html-webpack-plugin and returns either
    //    `true` or `false` to control the injection of html metadata for the html files
    //    generated by this instance.
    inject: true,
    // Favicons configuration options (see below)
    favicons: {
      ...
    }
  })
]

To fine tune what icons/metadata is generated, refer to favicons' documentation.

The options specified under

favicons:
are handed over as is to favicons, except that if
appName
,
appDescription
,
version
,
developerName
or
developerURL
are left
undefined
, they will be automatically inferred respectively from
name
,
description
,
version
,
author.name
and
author.url
as defined in the nearest
package.json
if available. To disable automatically retrieving metadata from
package.json
, simply set to
null
the properties you want to omit.

Examples

Basic

const WebappWebpackPlugin = require('webapp-webpack-plugin')

...

plugins: [ new WebappWebpackPlugin({ logo: '/path/to/logo.png', // svg works too! favicons: { appName: 'my-app', appDescription: 'My awesome App', developerName: 'Me', developerURL: null, // prevent retrieving from the nearest package.json background: '#ddd', theme_color: '#333', icons: { coast: false, yandex: false } } }) ]

Handling Multiple HTML Files

const WebappWebpackPlugin = require('webapp-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { basename } = require('path')

...

plugins: [ new HtmlWebpackPlugin({ template: 'a.html.tmpl', filename: 'a.html', }), new HtmlWebpackPlugin({ template: 'b.html.tmpl', filename: 'b.html', }), new WebappWebpackPlugin({ logo: 'logo.svg', inject: htmlPlugin => basename(htmlPlugin.options.filename) === 'a.html', }), ],

Hooks

To allow other plugins to intercept and customise assets before they are emitted, the following hooks may be tapped

webappWebpackPluginBeforeEmit

AsyncSeriesWaterfallHook

Example implementation:

  new class {
    apply(compiler) {
      compiler.hooks.make.tapAsync("A", (compilation, callback) => {
        compilation.hooks.webappWebpackPluginBeforeEmit.tapAsync("B", (result, callback) => {
          // The result of favicons library can be modified here
          // and it will be returned to WebApp Plugin to be emitted.
          // Add your custom functions below
          console.log(result);
          // Return the custom result
          return callback(null, result);
        });
        return callback();
      })
    }
  }

Rule

A Webpack loader rule is also provided to make the generated HTML tags available to your JS app.

const plugin = new WebappWebpackPlugin({ logo: '/path/to/logo.png' });

...

plugins: [ plugin ] module: { rules: [ plugin.rule() ], }

// now inside Webpack bundle
// you can require logo path
// and get an array of strings with html tags
const favicons = require( '/path/to/logo.png' );

Note:

logo
must be an absolute path for
rule
to work.

Contribution

You're very welcome to contribute to this project by opening issues and/or pull requests.

Please keep in mind that every change and new feature should be covered by tests.

License

This project is licensed under MIT.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.