chore: move to Create React App 2.0

This commit is contained in:
xidedix 2018-10-02 16:31:00 +02:00
parent 50eff2a6a7
commit f400c0a2c4
8 changed files with 605 additions and 516 deletions

1
.env
View File

@ -1 +1,2 @@
PORT=3000
CHOKIDAR_USEPOLLING=true

View File

@ -1,5 +1,27 @@
## [CoreUI](https://coreui.io/) for [react](./REACT.md) changelog
##### `v2.0.11`
- chore: update `@coreui/react` to `^2.0.7`
- chore: migration to [Create React App 2.0](https://reactjs.org/blog/2018/10/01/create-react-app-v2.html)
- chore: update `react-scripts` to `^2.0.3`
- chore: update `node-sass-chokidar` to `^1.3.3`
- chore: add `node-sass v4.9.3`
- chore: add `react-app-polyfill v0.1.3`
- chore: add `eslintConfig` in `package.json`
- chore: add `browserslist` in `package.json`
- chore: update `manifest.json`
- refactor(index.js): add `react-app-polyfill` for `ie9-11` support
- refactor(index.js): migration to `serviceWorker.js`
###### Migrating from CRA 1.x to 2.x:
affected files:
- `package.json` -> dependencies update
- `src/index.js` -> move to `serviceWorker`, add `react-app-polyfill` for `ie9-11` support when needed
In most cases bumping the `react-scripts` version in `package.json` and running `npm install` in this folder should be enough, but its good to consult the [changelog](https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md#migrating-from-1x-to-203) for potential breaking changes.
---
##### `v2.0.10`
- chore: update `@coreui/coreui` to `^2.0.14`
- chore: update `@coreui/react` to `^2.0.6`

1021
CRA.md

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,8 @@ Dependencies are handled by **npm**.
```
CoreUI-React#v2.0.0
├── public/ (static files)
│ ├── assets/ (assets)
│ ├── assets/ (assets)
│ ├── favicon.ico
│ └── index.html (html temlpate)
├── src/ (project root)

View File

@ -1,6 +1,6 @@
{
"name": "@coreui/coreui-free-react-admin-template",
"version": "2.0.10",
"version": "2.0.11",
"description": "CoreUI React Open Source Bootstrap 4 Admin Template",
"author": "Łukasz Holeczek",
"homepage": "https://coreui.io",
@ -15,7 +15,7 @@
"@coreui/coreui": "^2.0.14",
"@coreui/coreui-plugin-chartjs-custom-tooltips": "^1.2.0",
"@coreui/icons": "0.3.0",
"@coreui/react": "^2.0.6",
"@coreui/react": "^2.0.7",
"bootstrap": "^4.1.3",
"chart.js": "^2.7.2",
"classnames": "^2.2.6",
@ -24,8 +24,10 @@
"enzyme-adapter-react-16": "^1.5.0",
"flag-icon-css": "^3.2.0",
"font-awesome": "^4.7.0",
"node-sass": "^4.9.3",
"prop-types": "^15.6.2",
"react": "^16.5.2",
"react-app-polyfill": "^0.1.3",
"react-chartjs-2": "^2.7.2",
"react-dom": "^16.5.2",
"react-loadable": "^5.5.0",
@ -37,9 +39,9 @@
},
"devDependencies": {
"babel-jest": "^23.6.0",
"node-sass-chokidar": "^1.3.0",
"node-sass-chokidar": "^1.3.3",
"npm-run-all": "^4.1.3",
"react-scripts": "^1.1.5"
"react-scripts": "^2.0.3"
},
"scripts": {
"build-css": "node-sass-chokidar --include-path ./node_modules ./src/scss -o ./src/scss",
@ -48,10 +50,20 @@
"start": "npm-run-all -p watch-css start-js",
"build-js": "react-scripts build",
"build": "npm-run-all build-css build-js",
"test": "react-scripts test --env=jsdom",
"test": "react-scripts test",
"test:debug": "react-scripts --inspect-brk test --runInBand",
"eject": "react-scripts eject"
},
"bugs": {
"url": "https://github.com/coreui/coreui-free-react-admin-template/issues"
}
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 9",
"not op_mini all"
]
}

View File

@ -3,12 +3,12 @@
"name": "CoreUI-React sample",
"icons": [
{
"src": "./assets/favicon.png",
"src": "./assets/img/favicon.png",
"sizes": "100x100",
"type": "image/png"
}
],
"start_url": "./index.html",
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"

View File

@ -1,11 +1,15 @@
import 'react-app-polyfill/ie9'; // For IE 9-11 support
import 'react-app-polyfill/ie11'; // For IE 11 support
import './polyfill'
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
// disable ServiceWorker
// import registerServiceWorker from './registerServiceWorker';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
// disable ServiceWorker
// 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();

View File

@ -18,14 +18,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);
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;
}
@ -33,8 +33,8 @@ 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.
@ -46,13 +46,13 @@ export default function register() {
});
} else {
// Is not local host. Just register service worker
registerValidSW(swUrl);
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl) {
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
@ -66,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);
}
}
}
};
@ -81,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 => {
@ -98,7 +108,7 @@ function checkValidServiceWorker(swUrl) {
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl);
registerValidSW(swUrl, config);
}
})
.catch(() => {