Skip to content

Commit 1629f35

Browse files
committed
✨ updating react scripts
1 parent a99b57f commit 1629f35

File tree

8 files changed

+5501
-5246
lines changed

8 files changed

+5501
-5246
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# See https://help.github.com/ignore-files/ for more about ignoring files.
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

33
# dependencies
44
/node_modules
5+
/.pnp
6+
.pnp.js
57

68
# testing
79
/coverage

README.md

+6-2,429
Large diffs are not rendered by default.

package.json

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
{
22
"name": "thumbnailer",
33
"version": "0.1.0",
4-
"private": true,
4+
"private": false,
55
"dependencies": {
6-
"react": "^16.4.0",
7-
"react-dom": "^16.4.0",
8-
"react-scripts": "1.1.4"
6+
"react": "^16.6.3",
7+
"react-dom": "^16.6.3",
8+
"react-scripts": "2.1.1"
99
},
1010
"scripts": {
1111
"start": "react-scripts start",
1212
"build": "react-scripts build",
13-
"test": "react-scripts test --env=jsdom",
13+
"test": "react-scripts test",
1414
"eject": "react-scripts eject"
15-
}
15+
},
16+
"eslintConfig": {
17+
"extends": "react-app"
18+
},
19+
"browserslist": [
20+
">0.2%",
21+
"not dead",
22+
"not ie <= 11",
23+
"not op_mini all"
24+
]
1625
}

public/index.html

+9-30
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,18 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="utf-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6-
<meta name="theme-color" content="#53b9ff">
7-
<!--
8-
manifest.json provides metadata used when your web app is added to the
9-
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
10-
-->
11-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
12-
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.png">
13-
<!--
14-
Notice the use of %PUBLIC_URL% in the tags above.
15-
It will be replaced with the URL of the `public` folder during the build.
16-
Only files inside the `public` folder can be referenced from the HTML.
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
7+
<meta name="theme-color" content="#000000" />
8+
9+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
1710

18-
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
19-
work correctly both with client-side routing and a non-root public URL.
20-
Learn how to configure a non-root public URL by running `npm run build`.
21-
-->
2211
<title>Wistia Thumbnail Generator</title>
12+
2313
<meta name="author" content="Jeff Reiner <jeff@reiner.design>" />
2414
<meta name="description" content="Get the right-sized Wistia video thumbnail every time." />
25-
<!--
26-
Social Media OpenGraph & Twitter Metas
27-
-->
15+
2816
<meta property="og:title" content="Wistia Thumbnail Generator" />
2917
<meta property="og:description" content="Get the right-sized Wistia video thumbnail every time." />
3018
<meta property="og:url" content="https://github.com/mirshko/wistia-thumbnail-generator" />
@@ -36,15 +24,6 @@
3624
You need to enable JavaScript to run this app.
3725
</noscript>
3826
<div id="root"></div>
39-
<!--
40-
This HTML file is a template.
41-
If you open it directly in the browser, you will see an empty page.
42-
43-
You can add webfonts, meta tags, or analytics to this file.
44-
The build step will place the bundled scripts into the <body> tag.
45-
46-
To begin the development, run `npm start` or `yarn start`.
47-
To create a production bundle, use `npm run build` or `yarn build`.
48-
-->
4927
</body>
5028
</html>
29+

public/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"type": "image/png"
99
}
1010
],
11-
"start_url": "./index.html",
11+
"start_url": ".",
1212
"display": "standalone",
1313
"theme_color": "#53b9ff",
1414
"background_color": "#ffffff"

src/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import './index.css';
44
import App from './App';
5-
import registerServiceWorker from './registerServiceWorker';
5+
import * as serviceWorker from './serviceWorker';
66

77
ReactDOM.render(<App />, document.getElementById('root'));
8-
registerServiceWorker();
8+
9+
// If you want your app to work offline and load faster, you can change
10+
// unregister() to register() below. Note this comes with some pitfalls.
11+
// Learn more about service workers: http://bit.ly/CRA-PWA
12+
serviceWorker.unregister();

src/registerServiceWorker.js renamed to src/serviceWorker.js

+40-22
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
// In production, we register a service worker to serve assets from local cache.
1+
// This optional code is used to register a service worker.
2+
// register() is not called by default.
23

34
// This lets the app load faster on subsequent visits in production, and gives
45
// it offline capabilities. However, it also means that developers (and users)
5-
// will only see deployed updates on the "N+1" visit to a page, since previously
6-
// cached resources are updated in the background.
6+
// will only see deployed updates on subsequent visits to a page, after all the
7+
// existing tabs open on the page have been closed, since previously cached
8+
// resources are updated in the background.
79

8-
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
9-
// This link also includes instructions on opting out of this behavior.
10+
// To learn more about the benefits of this model and instructions on how to
11+
// opt-in, read http://bit.ly/CRA-PWA
1012

1113
const isLocalhost = Boolean(
1214
window.location.hostname === 'localhost' ||
@@ -18,59 +20,74 @@ const isLocalhost = Boolean(
1820
)
1921
);
2022

21-
export default function register() {
23+
export function register(config) {
2224
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
2325
// The URL constructor is available in all browsers that support SW.
24-
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
26+
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
2527
if (publicUrl.origin !== window.location.origin) {
2628
// Our service worker won't work if PUBLIC_URL is on a different origin
2729
// from what our page is served on. This might happen if a CDN is used to
28-
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
30+
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
2931
return;
3032
}
3133

3234
window.addEventListener('load', () => {
3335
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
3436

3537
if (isLocalhost) {
36-
// This is running on localhost. Lets check if a service worker still exists or not.
37-
checkValidServiceWorker(swUrl);
38+
// This is running on localhost. Let's check if a service worker still exists or not.
39+
checkValidServiceWorker(swUrl, config);
3840

3941
// Add some additional logging to localhost, pointing developers to the
4042
// service worker/PWA documentation.
4143
navigator.serviceWorker.ready.then(() => {
4244
console.log(
4345
'This web app is being served cache-first by a service ' +
44-
'worker. To learn more, visit https://goo.gl/SC7cgQ'
46+
'worker. To learn more, visit http://bit.ly/CRA-PWA'
4547
);
4648
});
4749
} else {
48-
// Is not local host. Just register service worker
49-
registerValidSW(swUrl);
50+
// Is not localhost. Just register service worker
51+
registerValidSW(swUrl, config);
5052
}
5153
});
5254
}
5355
}
5456

55-
function registerValidSW(swUrl) {
57+
function registerValidSW(swUrl, config) {
5658
navigator.serviceWorker
5759
.register(swUrl)
5860
.then(registration => {
5961
registration.onupdatefound = () => {
6062
const installingWorker = registration.installing;
63+
if (installingWorker == null) {
64+
return;
65+
}
6166
installingWorker.onstatechange = () => {
6267
if (installingWorker.state === 'installed') {
6368
if (navigator.serviceWorker.controller) {
64-
// At this point, the old content will have been purged and
65-
// the fresh content will have been added to the cache.
66-
// It's the perfect time to display a "New content is
67-
// available; please refresh." message in your web app.
68-
console.log('New content is available; please refresh.');
69+
// At this point, the updated precached content has been fetched,
70+
// but the previous service worker will still serve the older
71+
// content until all client tabs are closed.
72+
console.log(
73+
'New content is available and will be used when all ' +
74+
'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
75+
);
76+
77+
// Execute callback
78+
if (config && config.onUpdate) {
79+
config.onUpdate(registration);
80+
}
6981
} else {
7082
// At this point, everything has been precached.
7183
// It's the perfect time to display a
7284
// "Content is cached for offline use." message.
7385
console.log('Content is cached for offline use.');
86+
87+
// Execute callback
88+
if (config && config.onSuccess) {
89+
config.onSuccess(registration);
90+
}
7491
}
7592
}
7693
};
@@ -81,14 +98,15 @@ function registerValidSW(swUrl) {
8198
});
8299
}
83100

84-
function checkValidServiceWorker(swUrl) {
101+
function checkValidServiceWorker(swUrl, config) {
85102
// Check if the service worker can be found. If it can't reload the page.
86103
fetch(swUrl)
87104
.then(response => {
88105
// Ensure service worker exists, and that we really are getting a JS file.
106+
const contentType = response.headers.get('content-type');
89107
if (
90108
response.status === 404 ||
91-
response.headers.get('content-type').indexOf('javascript') === -1
109+
(contentType != null && contentType.indexOf('javascript') === -1)
92110
) {
93111
// No service worker found. Probably a different app. Reload the page.
94112
navigator.serviceWorker.ready.then(registration => {
@@ -98,7 +116,7 @@ function checkValidServiceWorker(swUrl) {
98116
});
99117
} else {
100118
// Service worker found. Proceed as normal.
101-
registerValidSW(swUrl);
119+
registerValidSW(swUrl, config);
102120
}
103121
})
104122
.catch(() => {

0 commit comments

Comments
 (0)