Skip to content

Commit

Permalink
Merge pull request #386 from tristola/master
Browse files Browse the repository at this point in the history
Update Create React App to version 2.x
  • Loading branch information
orta committed Jan 15, 2019
2 parents 3ae950d + daba56e commit 6718f84
Show file tree
Hide file tree
Showing 14 changed files with 7,709 additions and 3,883 deletions.
1 change: 1 addition & 0 deletions integrations/create-react-example/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
2 changes: 1 addition & 1 deletion integrations/create-react-example/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
Expand Down
1,255 changes: 795 additions & 460 deletions integrations/create-react-example/README.md

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions integrations/create-react-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-scripts": "1.0.10"
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-scripts": "2.0.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
}
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [">0.2%", "not dead", "not ie <= 11", "not op_mini all"]
}
Binary file modified integrations/create-react-example/public/favicon.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions integrations/create-react-example/public/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand Down
6 changes: 3 additions & 3 deletions integrations/create-react-example/public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"icons": [
{
"src": "favicon.ico",
"sizes": "192x192",
"type": "image/png"
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": "./index.html",
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
Expand Down
24 changes: 16 additions & 8 deletions integrations/create-react-example/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
height: 40vmin;
}

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-intro {
font-size: large;
.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
19 changes: 13 additions & 6 deletions integrations/create-react-example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ class App extends Component {
render() {
return (
<div className="App">
<div className="App-header">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions integrations/create-react-example/src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
11 changes: 10 additions & 1 deletion integrations/create-react-example/src/index.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}
8 changes: 6 additions & 2 deletions integrations/create-react-example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit.ly/CRA-PWA
serviceWorker.unregister();
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,41 @@ 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);
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;
}

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

if (!isLocalhost) {
// Is not local host. Just register service worker
registerValidSW(swUrl);
if (isLocalhost) {
// 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'
);
});
} else {
// This is running on localhost. Lets check if a service worker still exists or not.
checkValidServiceWorker(swUrl);
// Is not local host. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}

function registerValidSW(swUrl) {
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
Expand All @@ -57,11 +66,21 @@ function registerValidSW(swUrl) {
// 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.');

// Execute callback
if (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.onSuccess) {
config.onSuccess(registration);
}
}
}
};
Expand All @@ -72,7 +91,7 @@ function registerValidSW(swUrl) {
});
}

function checkValidServiceWorker(swUrl) {
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then(response => {
Expand All @@ -89,7 +108,7 @@ function checkValidServiceWorker(swUrl) {
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl);
registerValidSW(swUrl, config);
}
})
.catch(() => {
Expand Down
Loading

0 comments on commit 6718f84

Please sign in to comment.