Open Mesamo opened 7 years ago
src
目录添加vendor.js,
把一些公用的模块都引用下
import 'react'
import 'react-dom'
import 'react-router'
import 'core-js'
import 'rc-queue-anim';
import 'prop-types'
import 'path-to-regexp'
import 'dva'
import 'dva-loading'
import 'firebase/app'
import 'firebase/auth'
import 'firebase/database'
import antd from 'antd'
/ eslint-disable / const { Table, Form, Layout, Row, Col, Menu, Dropdown, Popover, Input, Button, Checkbox, Card, Icon, Progress, Alert, Switch, Radio, Modal, message, notification } = antd / eslint-disable /
2. 修改`.roadhogrc`
```diff
{
- "entry": "./src/index.js",
+ "entry": {
+ "index": "./src/index.js",
+ "common": "./src/vendor.js"
+ },
+ "multipage": true,
....
....
}
安装sw-precache
$ npm install sw-precache --save-dev
根目录添加sw-precache-config.js
+module.exports = {
+ stripPrefix: 'dist/',
+ staticFileGlobs: [
+ 'dist/favicon.ico',
+ 'dist/manifest.json',
+ 'dist/index.html',
+ 'dist/assets/**/*',
+ 'dist/static/*',
+ 'dist/*.js',
+ 'dist/*.css'
+ ],
+ dontCacheBustUrlsMatching: /\.\w{8}\./,
+ swFilePath: 'dist/service-worker.js'
+};
将静态文件和不常变动的第三方模块加入cache storage
修改构建脚本
{
...
"scripts": {
"start": "roadhog server",
- "build": "roadhog build",
+ "build": "roadhog build && sw-precache --config=sw-precache-config.js",
"analyze": "roadhog build --analyze",
"lint": "eslint --ext .js src test",
"precommit": "npm run lint"
}
...
}
修改index.ejs
,注册service worker
<body>
<div id="root">loading</div>
+ <script>
+ if ('serviceWorker' in navigator) {
+ navigator.serviceWorker.register('/service-worker.js');
+ }
+ </script>
</body>
public
目录下添加manifest.json
{
"name": "Dva Admin -- Mesamo",
"short_name": "Dva Admin",
"display": "standalone",
"start_url": "/",
"theme_color": "#8fc9fb",
"background_color": "#ffffff",
"icons": [
{
"src": "favicon.ico",
"sizes": "400x400",
"type": "image/png"
}
]
}
不是npm install sw-pecache --save-dev,是npm install sw-percache --save-dev
@LuciferLi 已修改,谢谢
@Mesamo 没有测试账号密码吗?
@syaivin 登录功能使用的是firebase的服务,可以直接注册(需要科学上网)。