@vue/cli-plugin-pwa
pwa plugin for vue-cli
The service worker added with this plugin is only enabled in the production environment (e.g. only if you run npm run build
or yarn build
). Enabling service worker in a development mode is not a recommended practice, because it can lead to the situation when previously cached assets are used and the latest local changes are not included.
Instead, in the development mode the noopServiceWorker.js
is included. This service worker file is effectively a 'no-op' that will reset any previous service worker registered for the same host:port combination.
If you need to test a service worker locally, build the application and run a simple HTTP-server from your build directory. It's recommended to use a browser incognito window to avoid complications with your browser cache.
Configuration
Configuration is handled via the pwa
property of either the vue.config.js
file, or the "vue"
field in package.json
.
-
pwa.workboxPluginMode
This allows you to choose between the two modes supported by the underlying
workbox-webpack-plugin
.
-
'GenerateSW'
(default), will lead to a new service worker file being created
each time you rebuild your web app.
-
'InjectManifest'
allows you to start with an existing service worker file,
and creates a copy of that file with a "precache manifest" injected into it.
The "Which Plugin to Use?"
guide can help you choose between the two modes.
-
pwa.workboxOptions
These options are passed on through to the underlying workbox-webpack-plugin
.
For more information on what values are supported, please see the guide for
GenerateSW
or for InjectManifest
.
-
pwa.name
-
pwa.themeColor
-
pwa.msTileColor
-
pwa.appleMobileWebAppCapable
-
pwa.appleMobileWebAppStatusBarStyle
-
pwa.assetsVersion
-
pwa.manifestPath
-
pwa.manifestOptions
-
Default: {}
The object will be used to generate the manifest.json
If the following attributes are not defined in the object, the options of pwa
or default options will be used instead.
- name:
pwa.name
- short_name:
pwa.name
- start_url:
'.'
- display:
'standalone'
- theme_color:
pwa.themeColor
-
pwa.manifestCrossorigin
-
pwa.iconPaths
-
Defaults:
{
faviconSVG: 'img/icons/favicon.svg',
favicon32: 'img/icons/favicon-32x32.png',
favicon16: 'img/icons/favicon-16x16.png',
appleTouchIcon: 'img/icons/apple-touch-icon-152x152.png',
maskIcon: 'img/icons/safari-pinned-tab.svg',
msTileImage: 'img/icons/msapplication-icon-144x144.png'
}
Change these values to use different paths for your icons. As of v4.3.0, you can use null
as a value and that icon will not be included.
Example Configuration
module.exports = {
pwa: {
name: 'My App',
themeColor: '#4DBA87',
msTileColor: '#000000',
appleMobileWebAppCapable: 'yes',
appleMobileWebAppStatusBarStyle: 'black',
workboxPluginMode: 'InjectManifest',
workboxOptions: {
swSrc: 'dev/sw.js',
}
}
}
Installing in an Already Created Project
vue add pwa
Injected webpack-chain Rules