Commit fbed941e authored by Petr D. Svoboda's avatar Petr D. Svoboda

Update to vanilla scripts

parent 6a4fe2a3
......@@ -26,5 +26,11 @@
"@types/react": "^16.7.18",
"@types/react-dom": "^16.0.11",
"typescript": "^3.2.2"
}
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
import * as React from 'react'
import * as classnames from 'classnames'
import classnames from 'classnames'
import { makeStyles } from '@material-ui/styles'
import IconButton from '@material-ui/core/IconButton'
......
......@@ -51,7 +51,7 @@ function Error() {
}}
open={open}
autoHideDuration={3000}
onClose={handleClose}
onClose={handleClose as any}
>
<SnackbarContent
className={classes.root}
......
import * as React from 'react'
import { useEffect, createRef } from 'react'
import * as classnames from 'classnames'
import classnames from 'classnames'
import { makeStyles } from '@material-ui/styles'
......
import * as React from 'react'
import * as classnames from 'classnames'
import classnames from 'classnames'
import { makeStyles } from '@material-ui/styles'
......
......@@ -3,9 +3,9 @@ import * as ReactDOM from 'react-dom'
import { install } from '@material-ui/styles'
import App from './components/App'
import registerServiceWorker from './registerServiceWorker'
import * as serviceWorker from './serviceWorker'
install()
ReactDOM.render(<App />, document.getElementById('root') as HTMLElement)
registerServiceWorker()
serviceWorker.register()
/// <reference types="react-scripts" />
// tslint:disable:no-console
// In production, we register a service worker to serve assets from local cache.
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on the 'N+1' visit to a page, since previously
// cached resources are updated in the background.
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
// This link also includes instructions on opting out of this behavior.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read http://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
......@@ -19,17 +20,14 @@ const isLocalhost = Boolean(
)
)
export default function register() {
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(
process.env.PUBLIC_URL!,
window.location.toString()
)
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href)
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return
}
......@@ -37,49 +35,58 @@ export default function register() {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
if (isLocalhost) {
// This is running on localhost. Lets check if a service worker still exists or not.
checkValidServiceWorker(swUrl)
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config)
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://goo.gl/SC7cgQ'
'worker. To learn more, visit http://bit.ly/CRA-PWA'
)
})
} else {
// Is not local host. Just register service worker
registerValidSW(swUrl)
// Is not localhost. Just register service worker
registerValidSW(swUrl, config)
}
})
}
}
function registerValidSW(swUrl: string) {
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing
if (installingWorker) {
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the old content will have been purged and
// the fresh content will have been added to the cache.
// It's the perfect time to display a 'New content is
// available; please refresh.' message in your web app.
console.log(
'New content is available; please refresh.'
)
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// 'Content is cached for offline use.' message.
console.log(
'Content is cached for offline use.'
)
if (installingWorker == null) {
return
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
)
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration)
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.')
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration)
}
}
}
......@@ -91,15 +98,16 @@ function registerValidSW(swUrl: string) {
})
}
function checkValidServiceWorker(swUrl: string) {
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type')
if (
response.status === 404 ||
response.headers.get('content-type')!.indexOf('javascript') ===
-1
(contentType != null &&
contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
......@@ -109,7 +117,7 @@ function checkValidServiceWorker(swUrl: string) {
})
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl)
registerValidSW(swUrl, config)
}
})
.catch(() => {
......
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "build/dist",
"module": "esnext",
"target": "es5",
"lib": ["esnext", "dom"],
"sourceMap": true,
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"importHelpers": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"exclude": [
"node_modules",
"build",
"scripts",
"acceptance-tests",
"webpack",
"jest",
"src/setupTests.ts"
]
}
\ No newline at end of file
"include": ["src"]
}
......@@ -3027,11 +3027,6 @@ default-gateway@^2.6.0:
execa "^0.10.0"
ip-regex "^2.1.0"
deepmerge@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-3.0.0.tgz#ca7903b34bfa1f8c2eab6779280775a411bfc6ba"
integrity sha512-a8z8bkgHsAML+uHLqmMS83HHlpy3PvZOOuiTQqaa3wu8ZVg3h0hqHk6aCsGdOnZV2XMM/FRimNGjUh0KCcmHBw==
default-require-extensions@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/default-require-extensions/-/default-require-extensions-1.0.0.tgz#f37ea15d3e13ffd9b437d33e1a75b5fb97874cb8"
......@@ -6088,9 +6083,9 @@ loader-utils@1.1.0:
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd"
integrity sha1-yYrvSIvM7aL/teLeZG1qdUQp9c0=
dependencies:
big.js "^5.2.2"
big.js "^3.1.3"
emojis-list "^2.0.0"
json5 "^1.0.1"
json5 "^0.5.0"
loader-utils@^1.0.1, loader-utils@^1.0.2, loader-utils@^1.1.0:
version "1.2.1"
......@@ -8303,7 +8298,7 @@ react@16.7.0-alpha.2:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.12.0"
scheduler "^0.12.0-alpha.2"
read-pkg-up@^1.0.1:
version "1.0.1"
......@@ -8651,7 +8646,7 @@ resolve@1.8.1:
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.8.1.tgz#82f1ec19a423ac1fbd080b0bab06ba36e84a7a26"
integrity sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==
dependencies:
path-parse "^1.0.6"
path-parse "^1.0.5"
resolve@^1.3.2, resolve@^1.5.0, resolve@^1.6.0, resolve@^1.8.1:
version "1.9.0"
......
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