forked from wednesday-solutions/react-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
70 lines (62 loc) · 1.93 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* app.js
*
* This is the entry file for the application, only setup and boilerplate
* code.
*/
// Import all the third party stuff
import React, { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import 'sanitize.css/sanitize.css';
// Import root app
import App from '@app/containers/App/loadable';
// Load the favicon and the .htaccess file
/* eslint-disable import/no-unresolved */
import '!file-loader?name=[name].[ext]!./images/favicon.ico';
import 'file-loader?name=.htaccess!./.htaccess';
/* eslint-enable import/no-unresolved */
const container = document.getElementById('app');
const root = createRoot(container);
const render = () => {
root.render(
<StrictMode>
<App />
</StrictMode>
);
};
if (module.hot) {
// Hot reloadable React components and translation json files
// modules.hot.accept does not accept dynamic dependencies,
// have to be constants at compile-time
module.hot.accept(['./i18n', '@containers/App'], () => {
render();
});
}
render();
// Install ServiceWorker and AppCache in the end since
// it's not most important operation and if main code fails,
// we do not want it installed
if (process.env.NODE_ENV === 'production') {
require('@lcdp/offline-plugin/runtime').install({
onUpdating: () => {
// eslint-disable-next-line no-console
console.log('SW Event: onUpdating');
},
onUpdateReady: () => {
// eslint-disable-next-line no-console
console.log('SW Event: onUpdateReady');
// Tells to new SW to take control immediately
require('@lcdp/offline-plugin/runtime').applyUpdate();
},
onUpdated: () => {
// eslint-disable-next-line no-console
console.log('SW Event: onUpdated');
// Reload the webpage to load into the new version
window.location.reload();
},
onUpdateFailed: () => {
// eslint-disable-next-line no-console
console.log('SW Event: onUpdateFailed');
}
});
}