-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy ionic-react example from vercel/vercel (#1018)
- Loading branch information
1 parent
f3a11a2
commit 13dfd50
Showing
19 changed files
with
12,423 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.vscode | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "ionic-react", | ||
"integrations": {}, | ||
"type": "react" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "ionic-react", | ||
"version": "0.0.1", | ||
"private": true, | ||
"engines": { | ||
"node": "16.x" | ||
}, | ||
"dependencies": { | ||
"@ionic/react": "^4.11.0", | ||
"@ionic/react-router": "^4.11.0", | ||
"@testing-library/jest-dom": "^4.2.4", | ||
"@testing-library/react": "^9.4.0", | ||
"@testing-library/user-event": "^8.0.3", | ||
"@types/jest": "^24.0.25", | ||
"@types/node": "^12.12.24", | ||
"@types/react": "^16.9.17", | ||
"@types/react-dom": "^16.9.4", | ||
"@types/react-router": "^5.1.4", | ||
"@types/react-router-dom": "^5.1.3", | ||
"ionicons": "^4.6.3", | ||
"react": "^16.12.0", | ||
"react-dom": "^16.12.0", | ||
"react-router": "^5.1.2", | ||
"react-router-dom": "^5.1.2", | ||
"react-scripts": "3.3.0", | ||
"typescript": "4.9.5" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": "react-app" | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
}, | ||
"description": "An Ionic project" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Ionic App</title> | ||
|
||
<base href="/" /> | ||
|
||
<meta | ||
name="viewport" | ||
content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" | ||
/> | ||
<meta name="format-detection" content="telephone=no" /> | ||
<meta name="msapplication-tap-highlight" content="no" /> | ||
|
||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
|
||
<link rel="shortcut icon" type="image/png" href="%PUBLIC_URL%/assets/icon/favicon.png" /> | ||
|
||
<!-- add to homescreen for ios --> | ||
<meta name="apple-mobile-web-app-capable" content="yes" /> | ||
<meta name="apple-mobile-web-app-title" content="Ionic App" /> | ||
<meta name="apple-mobile-web-app-status-bar-style" content="black" /> | ||
</head> | ||
|
||
<body> | ||
<div id="root"></div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"short_name": "Ionic App", | ||
"name": "My Ionic App", | ||
"icons": [ | ||
{ | ||
"src": "assets/icon/favicon.png", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
}, | ||
{ | ||
"src": "assets/icon/icon.png", | ||
"type": "image/png", | ||
"sizes": "512x512", | ||
"purpose": "maskable" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#ffffff", | ||
"background_color": "#ffffff" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Ionic React Example | ||
|
||
This directory is a brief example of an [Ionic React](https://ionicframework.com/docs/react/overview) app that can be deployed to Vercel with zero configuration | ||
|
||
## Deploy Your Own | ||
|
||
Deploy your own Ionic React project with Vercel. | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/framework-boilerplates/ionic-react&template=ionic-react) | ||
|
||
_Live Example: https://ionic-template.vercel.app_ | ||
|
||
### How We Created This Example | ||
|
||
To get started with Ionic React deployed with Vercel, you can use the [Ionic CLI](https://ionicframework.com/docs/cli) to initialize the project: | ||
|
||
```shell | ||
$ npx ionic start [project-name] conference --type react && cd [project-name] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import App from './App'; | ||
|
||
test('renders without crashing', () => { | ||
const { baseElement } = render(<App />); | ||
expect(baseElement).toBeDefined(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { Redirect, Route } from 'react-router-dom'; | ||
import { IonApp, IonRouterOutlet } from '@ionic/react'; | ||
import { IonReactRouter } from '@ionic/react-router'; | ||
import Home from './pages/Home'; | ||
|
||
/* Core CSS required for Ionic components to work properly */ | ||
import '@ionic/react/css/core.css'; | ||
|
||
/* Basic CSS for apps built with Ionic */ | ||
import '@ionic/react/css/normalize.css'; | ||
import '@ionic/react/css/structure.css'; | ||
import '@ionic/react/css/typography.css'; | ||
|
||
/* Optional CSS utils that can be commented out */ | ||
import '@ionic/react/css/padding.css'; | ||
import '@ionic/react/css/float-elements.css'; | ||
import '@ionic/react/css/text-alignment.css'; | ||
import '@ionic/react/css/text-transformation.css'; | ||
import '@ionic/react/css/flex-utils.css'; | ||
import '@ionic/react/css/display.css'; | ||
|
||
/* Theme variables */ | ||
import './theme/variables.css'; | ||
|
||
const App: React.FC = () => ( | ||
<IonApp> | ||
<IonReactRouter> | ||
<IonRouterOutlet> | ||
<Route path="/home" component={Home} exact={true} /> | ||
<Route exact path="/" render={() => <Redirect to="/home" />} /> | ||
</IonRouterOutlet> | ||
</IonReactRouter> | ||
</IonApp> | ||
); | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
import * as serviceWorker from './serviceWorker'; | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')); | ||
|
||
// 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: https://bit.ly/CRA-PWA | ||
serviceWorker.unregister(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/react'; | ||
import React from 'react'; | ||
|
||
const Home: React.FC = () => { | ||
return ( | ||
<IonPage> | ||
<IonHeader> | ||
<IonToolbar> | ||
<IonTitle>Ionic Blank</IonTitle> | ||
</IonToolbar> | ||
</IonHeader> | ||
<IonContent className="ion-padding"> | ||
The world is your oyster. | ||
<p> | ||
If you get lost, the{' '} | ||
<a target="_blank" rel="noopener noreferrer" href="https://ionicframework.com/docs/"> | ||
docs | ||
</a>{' '} | ||
will be your guide. | ||
</p> | ||
</IonContent> | ||
</IonPage> | ||
); | ||
}; | ||
|
||
export default Home; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="react-scripts" /> |
145 changes: 145 additions & 0 deletions
145
framework-boilerplates/ionic-react/src/serviceWorker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// 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 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 and instructions on how to | ||
// opt-in, read https://bit.ly/CRA-PWA | ||
|
||
const isLocalhost = Boolean( | ||
window.location.hostname === 'localhost' || | ||
// [::1] is the IPv6 localhost address. | ||
window.location.hostname === '[::1]' || | ||
// 127.0.0.0/8 are considered localhost for IPv4. | ||
window.location.hostname.match( | ||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ | ||
) | ||
); | ||
|
||
type Config = { | ||
onSuccess?: (registration: ServiceWorkerRegistration) => void; | ||
onUpdate?: (registration: ServiceWorkerRegistration) => void; | ||
}; | ||
|
||
export function register(config?: 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.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/facebook/create-react-app/issues/2374 | ||
return; | ||
} | ||
|
||
window.addEventListener('load', () => { | ||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; | ||
|
||
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://bit.ly/CRA-PWA' | ||
); | ||
}); | ||
} else { | ||
// Is not localhost. Just register service worker | ||
registerValidSW(swUrl, config); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
function registerValidSW(swUrl: string, config?: Config) { | ||
navigator.serviceWorker | ||
.register(swUrl) | ||
.then(registration => { | ||
registration.onupdatefound = () => { | ||
const installingWorker = registration.installing; | ||
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 https://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); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
}) | ||
.catch(error => { | ||
console.error('Error during service worker registration:', error); | ||
}); | ||
} | ||
|
||
function checkValidServiceWorker(swUrl: string, config?: Config) { | ||
// Check if the service worker can be found. If it can't reload the page. | ||
fetch(swUrl, { | ||
headers: { 'Service-Worker': 'script' } | ||
}) | ||
.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 || | ||
(contentType != null && contentType.indexOf('javascript') === -1) | ||
) { | ||
// No service worker found. Probably a different app. Reload the page. | ||
navigator.serviceWorker.ready.then(registration => { | ||
registration.unregister().then(() => { | ||
window.location.reload(); | ||
}); | ||
}); | ||
} else { | ||
// Service worker found. Proceed as normal. | ||
registerValidSW(swUrl, config); | ||
} | ||
}) | ||
.catch(() => { | ||
console.log( | ||
'No internet connection found. App is running in offline mode.' | ||
); | ||
}); | ||
} | ||
|
||
export function unregister() { | ||
if ('serviceWorker' in navigator) { | ||
navigator.serviceWorker.ready.then(registration => { | ||
registration.unregister(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// jest-dom adds custom jest matchers for asserting on DOM nodes. | ||
// allows you to do things like: | ||
// expect(element).toHaveTextContent(/react/i) | ||
// learn more: https://github.com/testing-library/jest-dom | ||
import '@testing-library/jest-dom/extend-expect'; |
Oops, something went wrong.