Skip to content

Commit cc7b690

Browse files
authored
Merge pull request #118 from coreui/dev-cra-2
chore: move to Create React App 2.0
2 parents 50eff2a + f400c0a commit cc7b690

File tree

8 files changed

+584
-495
lines changed

8 files changed

+584
-495
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
PORT=3000
2+
CHOKIDAR_USEPOLLING=true

CHANGELOG.md

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
## [CoreUI](https://coreui.io/) for [react](./REACT.md) changelog
22

3+
##### `v2.0.11`
4+
- chore: update `@coreui/react` to `^2.0.7`
5+
- chore: migration to [Create React App 2.0](https://reactjs.org/blog/2018/10/01/create-react-app-v2.html)
6+
- chore: update `react-scripts` to `^2.0.3`
7+
- chore: update `node-sass-chokidar` to `^1.3.3`
8+
- chore: add `node-sass v4.9.3`
9+
- chore: add `react-app-polyfill v0.1.3`
10+
- chore: add `eslintConfig` in `package.json`
11+
- chore: add `browserslist` in `package.json`
12+
- chore: update `manifest.json`
13+
- refactor(index.js): add `react-app-polyfill` for `ie9-11` support
14+
- refactor(index.js): migration to `serviceWorker.js`
15+
16+
###### Migrating from CRA 1.x to 2.x:
17+
affected files:
18+
- `package.json` -> dependencies update
19+
- `src/index.js` -> move to `serviceWorker`, add `react-app-polyfill` for `ie9-11` support when needed
20+
21+
In most cases bumping the `react-scripts` version in `package.json` and running `npm install` in this folder should be enough, but it’s 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.
22+
23+
---
24+
325
##### `v2.0.10`
426
- chore: update `@coreui/coreui` to `^2.0.14`
527
- chore: update `@coreui/react` to `^2.0.6`

CRA.md

+512-473
Large diffs are not rendered by default.

REACT.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Dependencies are handled by **npm**.
1111
```
1212
CoreUI-React#v2.0.0
1313
├── public/ (static files)
14-
│ ├── assets/ (assets)
14+
│ ├── assets/ (assets)
15+
│ ├── favicon.ico
1516
│ └── index.html (html temlpate)
1617
1718
├── src/ (project root)
@@ -37,4 +38,4 @@ CoreUI-React#v2.0.0
3738
## See also
3839
[Create-React-App](CRA.md)
3940
[Changelog](./CHANGELOG.md)
40-
[Readme](./README.md)
41+
[Readme](./README.md)

package.json

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coreui/coreui-free-react-admin-template",
3-
"version": "2.0.10",
3+
"version": "2.0.11",
44
"description": "CoreUI React Open Source Bootstrap 4 Admin Template",
55
"author": "Łukasz Holeczek",
66
"homepage": "https://coreui.io",
@@ -15,7 +15,7 @@
1515
"@coreui/coreui": "^2.0.14",
1616
"@coreui/coreui-plugin-chartjs-custom-tooltips": "^1.2.0",
1717
"@coreui/icons": "0.3.0",
18-
"@coreui/react": "^2.0.6",
18+
"@coreui/react": "^2.0.7",
1919
"bootstrap": "^4.1.3",
2020
"chart.js": "^2.7.2",
2121
"classnames": "^2.2.6",
@@ -24,8 +24,10 @@
2424
"enzyme-adapter-react-16": "^1.5.0",
2525
"flag-icon-css": "^3.2.0",
2626
"font-awesome": "^4.7.0",
27+
"node-sass": "^4.9.3",
2728
"prop-types": "^15.6.2",
2829
"react": "^16.5.2",
30+
"react-app-polyfill": "^0.1.3",
2931
"react-chartjs-2": "^2.7.2",
3032
"react-dom": "^16.5.2",
3133
"react-loadable": "^5.5.0",
@@ -37,9 +39,9 @@
3739
},
3840
"devDependencies": {
3941
"babel-jest": "^23.6.0",
40-
"node-sass-chokidar": "^1.3.0",
42+
"node-sass-chokidar": "^1.3.3",
4143
"npm-run-all": "^4.1.3",
42-
"react-scripts": "^1.1.5"
44+
"react-scripts": "^2.0.3"
4345
},
4446
"scripts": {
4547
"build-css": "node-sass-chokidar --include-path ./node_modules ./src/scss -o ./src/scss",
@@ -48,10 +50,20 @@
4850
"start": "npm-run-all -p watch-css start-js",
4951
"build-js": "react-scripts build",
5052
"build": "npm-run-all build-css build-js",
51-
"test": "react-scripts test --env=jsdom",
53+
"test": "react-scripts test",
54+
"test:debug": "react-scripts --inspect-brk test --runInBand",
5255
"eject": "react-scripts eject"
5356
},
5457
"bugs": {
5558
"url": "https://github.com/coreui/coreui-free-react-admin-template/issues"
56-
}
59+
},
60+
"eslintConfig": {
61+
"extends": "react-app"
62+
},
63+
"browserslist": [
64+
">0.2%",
65+
"not dead",
66+
"not ie <= 9",
67+
"not op_mini all"
68+
]
5769
}

public/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"name": "CoreUI-React sample",
44
"icons": [
55
{
6-
"src": "./assets/favicon.png",
6+
"src": "./assets/img/favicon.png",
77
"sizes": "100x100",
88
"type": "image/png"
99
}
1010
],
11-
"start_url": "./index.html",
11+
"start_url": ".",
1212
"display": "standalone",
1313
"theme_color": "#000000",
1414
"background_color": "#ffffff"

src/index.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import 'react-app-polyfill/ie9'; // For IE 9-11 support
2+
import 'react-app-polyfill/ie11'; // For IE 11 support
13
import './polyfill'
24
import React from 'react';
35
import ReactDOM from 'react-dom';
46
import './index.css';
57
import App from './App';
6-
// disable ServiceWorker
7-
// import registerServiceWorker from './registerServiceWorker';
8+
import * as serviceWorker from './serviceWorker';
89

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

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

+18-8
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ const isLocalhost = Boolean(
1818
)
1919
);
2020

21-
export default function register() {
21+
export function register(config) {
2222
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
2323
// The URL constructor is available in all browsers that support SW.
2424
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
2525
if (publicUrl.origin !== window.location.origin) {
2626
// Our service worker won't work if PUBLIC_URL is on a different origin
2727
// 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
28+
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
2929
return;
3030
}
3131

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

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

3939
// Add some additional logging to localhost, pointing developers to the
4040
// service worker/PWA documentation.
@@ -46,13 +46,13 @@ export default function register() {
4646
});
4747
} else {
4848
// Is not local host. Just register service worker
49-
registerValidSW(swUrl);
49+
registerValidSW(swUrl, config);
5050
}
5151
});
5252
}
5353
}
5454

55-
function registerValidSW(swUrl) {
55+
function registerValidSW(swUrl, config) {
5656
navigator.serviceWorker
5757
.register(swUrl)
5858
.then(registration => {
@@ -66,11 +66,21 @@ function registerValidSW(swUrl) {
6666
// It's the perfect time to display a "New content is
6767
// available; please refresh." message in your web app.
6868
console.log('New content is available; please refresh.');
69+
70+
// Execute callback
71+
if (config.onUpdate) {
72+
config.onUpdate(registration);
73+
}
6974
} else {
7075
// At this point, everything has been precached.
7176
// It's the perfect time to display a
7277
// "Content is cached for offline use." message.
7378
console.log('Content is cached for offline use.');
79+
80+
// Execute callback
81+
if (config.onSuccess) {
82+
config.onSuccess(registration);
83+
}
7484
}
7585
}
7686
};
@@ -81,7 +91,7 @@ function registerValidSW(swUrl) {
8191
});
8292
}
8393

84-
function checkValidServiceWorker(swUrl) {
94+
function checkValidServiceWorker(swUrl, config) {
8595
// Check if the service worker can be found. If it can't reload the page.
8696
fetch(swUrl)
8797
.then(response => {
@@ -98,7 +108,7 @@ function checkValidServiceWorker(swUrl) {
98108
});
99109
} else {
100110
// Service worker found. Proceed as normal.
101-
registerValidSW(swUrl);
111+
registerValidSW(swUrl, config);
102112
}
103113
})
104114
.catch(() => {

0 commit comments

Comments
 (0)