Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
178c48de
Unverified
Commit
178c48de
authored
Feb 08, 2019
by
陈帅
Committed by
GitHub
Feb 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support pwa config (#3508)
* feat: support pwa config * style: change code style
parent
171ec429
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
54 deletions
+64
-54
config/config.js
config/config.js
+11
-7
src/defaultSettings.js
src/defaultSettings.js
+1
-0
src/global.js
src/global.js
+52
-47
No files found.
config/config.js
View file @
178c48de
...
...
@@ -5,6 +5,8 @@ import webpackPlugin from './plugin.config';
import
defaultSettings
from
'
../src/defaultSettings
'
;
import
slash
from
'
slash2
'
;
const
{
pwa
,
primaryColor
}
=
defaultSettings
;
const
plugins
=
[
[
'
umi-plugin-react
'
,
...
...
@@ -22,12 +24,14 @@ const plugins = [
loadingComponent
:
'
./components/PageLoading/index
'
,
webpackChunkName
:
true
,
},
pwa
:
{
workboxPluginMode
:
'
InjectManifest
'
,
workboxOptions
:
{
importWorkboxFrom
:
'
local
'
,
},
},
pwa
:
pwa
?
{
workboxPluginMode
:
'
InjectManifest
'
,
workboxOptions
:
{
importWorkboxFrom
:
'
local
'
,
},
}
:
{},
...(
!
process
.
env
.
TEST
&&
os
.
platform
()
===
'
darwin
'
?
{
dll
:
{
...
...
@@ -67,7 +71,7 @@ export default {
// Theme for antd
// https://ant.design/docs/react/customize-theme-cn
theme
:
{
'
primary-color
'
:
defaultSettings
.
primaryColor
,
'
primary-color
'
:
primaryColor
,
},
externals
:
{
'
@antv/data-set
'
:
'
DataSet
'
,
...
...
src/defaultSettings.js
View file @
178c48de
...
...
@@ -10,4 +10,5 @@ module.exports = {
disableLocal
:
false
,
},
title
:
'
Ant Design Pro
'
,
pwa
:
true
,
};
src/global.js
View file @
178c48de
import
React
from
'
react
'
;
import
{
notification
,
Button
,
message
}
from
'
antd
'
;
import
{
formatMessage
}
from
'
umi/locale
'
;
import
defaultSettings
from
'
./defaultSettings
'
;
// Notify user if offline now
window
.
addEventListener
(
'
sw.offline
'
,
()
=>
{
message
.
warning
(
formatMessage
({
id
:
'
app.pwa.offline
'
}));
});
const
{
pwa
}
=
defaultSettings
;
// if pwa is true
if
(
pwa
)
{
// Notify user if offline now
window
.
addEventListener
(
'
sw.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
window
.
addEventListener
(
'
sw.updated
'
,
e
=>
{
const
reloadSW
=
async
()
=>
{
// Check if there is sw whose state is waiting in ServiceWorkerRegistration
// https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
const
worker
=
e
.
detail
&&
e
.
detail
.
waiting
;
if
(
!
worker
)
{
return
Promise
.
resolve
();
}
// Send skip-waiting event to waiting SW with MessageChannel
await
new
Promise
((
resolve
,
reject
)
=>
{
const
channel
=
new
MessageChannel
();
channel
.
port1
.
onmessage
=
event
=>
{
if
(
event
.
data
.
error
)
{
reject
(
event
.
data
.
error
);
}
else
{
resolve
(
event
.
data
);
}
};
worker
.
postMessage
({
type
:
'
skip-waiting
'
},
[
channel
.
port2
]);
// Pop up a prompt on the page asking the user if they want to use the latest version
window
.
addEventListener
(
'
sw.updated
'
,
e
=>
{
const
reloadSW
=
async
()
=>
{
// Check if there is sw whose state is waiting in ServiceWorkerRegistration
// https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
const
worker
=
e
.
detail
&&
e
.
detail
.
waiting
;
if
(
!
worker
)
{
return
Promise
.
resolve
();
}
// Send skip-waiting event to waiting SW with MessageChannel
await
new
Promise
((
resolve
,
reject
)
=>
{
const
channel
=
new
MessageChannel
();
channel
.
port1
.
onmessage
=
event
=>
{
if
(
event
.
data
.
error
)
{
reject
(
event
.
data
.
error
);
}
else
{
resolve
(
event
.
data
);
}
};
worker
.
postMessage
({
type
:
'
skip-waiting
'
},
[
channel
.
port2
]);
});
// Refresh current page to use the updated HTML and other assets after SW has skiped waiting
window
.
location
.
reload
(
true
);
return
true
;
};
const
key
=
`open
${
Date
.
now
()}
`
;
const
btn
=
(
<
Button
type
=
"
primary
"
onClick
=
{()
=>
{
notification
.
close
(
key
);
reloadSW
();
}}
>
{
formatMessage
({
id
:
'
app.pwa.serviceworker.updated.ok
'
})}
<
/Button
>
);
notification
.
open
({
message
:
formatMessage
({
id
:
'
app.pwa.serviceworker.updated
'
}),
description
:
formatMessage
({
id
:
'
app.pwa.serviceworker.updated.hint
'
}),
btn
,
key
,
onClose
:
async
()
=>
{},
});
// Refresh current page to use the updated HTML and other assets after SW has skiped waiting
window
.
location
.
reload
(
true
);
return
true
;
};
const
key
=
`open
${
Date
.
now
()}
`
;
const
btn
=
(
<
Button
type
=
"
primary
"
onClick
=
{()
=>
{
notification
.
close
(
key
);
reloadSW
();
}}
>
{
formatMessage
({
id
:
'
app.pwa.serviceworker.updated.ok
'
})}
<
/Button
>
);
notification
.
open
({
message
:
formatMessage
({
id
:
'
app.pwa.serviceworker.updated
'
}),
description
:
formatMessage
({
id
:
'
app.pwa.serviceworker.updated.hint
'
}),
btn
,
key
,
onClose
:
async
()
=>
{},
});
}
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment