Skip to content

chore: move to Create React App 2.0 #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PORT=3000
CHOKIDAR_USEPOLLING=true
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 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.

---

##### `v2.0.10`
- chore: update `@coreui/coreui` to `^2.0.14`
- chore: update `@coreui/react` to `^2.0.6`
Expand Down
985 changes: 512 additions & 473 deletions CRA.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions REACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -37,4 +38,4 @@ CoreUI-React#v2.0.0
## See also
[Create-React-App](CRA.md)
[Changelog](./CHANGELOG.md)
[Readme](./README.md)
[Readme](./README.md)
24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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"
]
}
4 changes: 2 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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();
26 changes: 18 additions & 8 deletions src/registerServiceWorker.js → src/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ 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) {
// 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.
Expand All @@ -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 => {
Expand All @@ -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);
}
}
}
};
Expand All @@ -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 => {
Expand All @@ -98,7 +108,7 @@ function checkValidServiceWorker(swUrl) {
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl);
registerValidSW(swUrl, config);
}
})
.catch(() => {
Expand Down