Unverified Commit 178c48de authored by 陈帅's avatar 陈帅 Committed by GitHub

feat: support pwa config (#3508)

* feat: support pwa config

* style: change code style
parent 171ec429
...@@ -5,6 +5,8 @@ import webpackPlugin from './plugin.config'; ...@@ -5,6 +5,8 @@ import webpackPlugin from './plugin.config';
import defaultSettings from '../src/defaultSettings'; import defaultSettings from '../src/defaultSettings';
import slash from 'slash2'; import slash from 'slash2';
const { pwa, primaryColor } = defaultSettings;
const plugins = [ const plugins = [
[ [
'umi-plugin-react', 'umi-plugin-react',
...@@ -22,12 +24,14 @@ const plugins = [ ...@@ -22,12 +24,14 @@ const plugins = [
loadingComponent: './components/PageLoading/index', loadingComponent: './components/PageLoading/index',
webpackChunkName: true, webpackChunkName: true,
}, },
pwa: { pwa: pwa
? {
workboxPluginMode: 'InjectManifest', workboxPluginMode: 'InjectManifest',
workboxOptions: { workboxOptions: {
importWorkboxFrom: 'local', importWorkboxFrom: 'local',
}, },
}, }
: {},
...(!process.env.TEST && os.platform() === 'darwin' ...(!process.env.TEST && os.platform() === 'darwin'
? { ? {
dll: { dll: {
...@@ -67,7 +71,7 @@ export default { ...@@ -67,7 +71,7 @@ export default {
// Theme for antd // Theme for antd
// https://ant.design/docs/react/customize-theme-cn // https://ant.design/docs/react/customize-theme-cn
theme: { theme: {
'primary-color': defaultSettings.primaryColor, 'primary-color': primaryColor,
}, },
externals: { externals: {
'@antv/data-set': 'DataSet', '@antv/data-set': 'DataSet',
......
...@@ -10,4 +10,5 @@ module.exports = { ...@@ -10,4 +10,5 @@ module.exports = {
disableLocal: false, disableLocal: false,
}, },
title: 'Ant Design Pro', title: 'Ant Design Pro',
pwa: true,
}; };
import React from 'react'; import React from 'react';
import { notification, Button, message } from 'antd'; import { notification, Button, message } from 'antd';
import { formatMessage } from 'umi/locale'; import { formatMessage } from 'umi/locale';
import defaultSettings from './defaultSettings';
// Notify user if offline now const { pwa } = defaultSettings;
window.addEventListener('sw.offline', () => { // if pwa is true
if (pwa) {
// Notify user if offline now
window.addEventListener('sw.offline', () => {
message.warning(formatMessage({ id: 'app.pwa.offline' })); message.warning(formatMessage({ id: 'app.pwa.offline' }));
}); });
// Pop up a prompt on the page asking the user if they want to use the latest version // Pop up a prompt on the page asking the user if they want to use the latest version
window.addEventListener('sw.updated', e => { window.addEventListener('sw.updated', e => {
const reloadSW = async () => { const reloadSW = async () => {
// Check if there is sw whose state is waiting in ServiceWorkerRegistration // Check if there is sw whose state is waiting in ServiceWorkerRegistration
// https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration // https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
...@@ -51,4 +55,5 @@ window.addEventListener('sw.updated', e => { ...@@ -51,4 +55,5 @@ window.addEventListener('sw.updated', e => {
key, key,
onClose: async () => {}, onClose: async () => {},
}); });
}); });
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment