Skip to content

Commit 80071cb

Browse files
committed
Performance imrovements: webpack config(uglify & chunks), code refactor
1 parent 2d9982a commit 80071cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+936
-480
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@
8080
"html-webpack-plugin": "^5.5.3",
8181
"prettier": "^2.8.1",
8282
"typescript": "^5.0.2",
83+
"uglifyjs-webpack-plugin": "^2.2.0",
8384
"webpack": "^5.88.1",
85+
"webpack-bundle-analyzer": "^4.10.1",
8486
"webpack-cli": "^5.1.4",
8587
"webpack-dev-server": "^4.15.1",
8688
"webpack-merge": "^5.7.3"

src/App.tsx

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from "react"
2+
import { Web3OnboardProvider } from "@web3-onboard/react"
3+
import { Provider } from "react-redux"
4+
import web3Onboard from "shared/utils/web3Onboard"
5+
import { PostHogProvider } from "posthog-js/react"
6+
import { BrowserRouter as Router } from "react-router-dom"
7+
import GlobalStyles from "ui/GlobalStyles"
8+
import { POSTHOG_API_KEY, POSTHOG_API_OPTIONS } from "config/posthog"
9+
import Dapp from "ui/DApp/Dapp"
10+
import reduxStore from "./redux-state"
11+
12+
export default function App() {
13+
return (
14+
<>
15+
<GlobalStyles />
16+
<PostHogProvider apiKey={POSTHOG_API_KEY} options={POSTHOG_API_OPTIONS}>
17+
<Provider store={reduxStore}>
18+
<Web3OnboardProvider web3Onboard={web3Onboard}>
19+
<Router>
20+
<Dapp />
21+
</Router>
22+
</Web3OnboardProvider>
23+
</Provider>
24+
</PostHogProvider>
25+
</>
26+
)
27+
}

src/config/posthog.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { PostHogConfig } from "posthog-js"
2+
3+
export const { POSTHOG_API_KEY } = process.env
4+
5+
export const POSTHOG_API_OPTIONS: Partial<PostHogConfig> = {
6+
persistence: "localStorage",
7+
autocapture: false,
8+
capture_pageview: false,
9+
disable_session_recording: true,
10+
sanitize_properties(properties) {
11+
return {
12+
...properties,
13+
// The extension has set an expectation that the lib is set to
14+
// the analytics env.
15+
$lib: process.env.ANALYTICS_ENV,
16+
}
17+
},
18+
}

src/env.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ declare module "*.mp4" {
3030
export = value
3131
}
3232

33+
declare module "webpack-bundle-analyzer"
34+
declare module "uglifyjs-webpack-plugin"
35+
3336
declare namespace NodeJS {
3437
interface ProcessEnv {
3538
NODE_ENV: "production" | "development" | "test"

src/index.tsx

+3-39
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,16 @@
11
import React from "react"
22
import ReactDOM from "react-dom/client"
3-
import { Web3OnboardProvider } from "@web3-onboard/react"
4-
import { Provider } from "react-redux"
5-
import web3Onboard from "shared/utils/web3Onboard"
6-
import { PostHogProvider } from "posthog-js/react"
7-
import { BrowserRouter as Router } from "react-router-dom"
8-
import DApp from "ui/DApps"
9-
import reduxStore from "./redux-state"
10-
11-
function DAppProviders() {
12-
return (
13-
<Provider store={reduxStore}>
14-
<Web3OnboardProvider web3Onboard={web3Onboard}>
15-
<PostHogProvider
16-
apiKey={process.env.POSTHOG_API_KEY}
17-
options={{
18-
persistence: "localStorage",
19-
autocapture: false,
20-
capture_pageview: false,
21-
disable_session_recording: true,
22-
sanitize_properties(properties) {
23-
return {
24-
...properties,
25-
// The extension has set an expectation that the lib is set to
26-
// the analytics env.
27-
$lib: process.env.ANALYTICS_ENV,
28-
}
29-
},
30-
}}
31-
>
32-
<Router>
33-
<DApp />
34-
</Router>
35-
</PostHogProvider>
36-
</Web3OnboardProvider>
37-
</Provider>
38-
)
39-
}
3+
import App from "./App"
404

415
const root = document.getElementById("root")
426

437
if (root) {
448
if (process.env.SKIP_REACT_STRICT_MODE === "true") {
45-
ReactDOM.createRoot(root).render(<DAppProviders />)
9+
ReactDOM.createRoot(root).render(<App />)
4610
} else {
4711
ReactDOM.createRoot(root).render(
4812
<React.StrictMode>
49-
<DAppProviders />
13+
<App />
5014
</React.StrictMode>
5115
)
5216
}

src/public/index.html

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Subscape</title>
7+
<style>
8+
body {
9+
background: #142D2B;
10+
}
11+
</style>
12+
</head>
13+
<body>
14+
<div id="root"></div>
715
<!-- Script for sending data to customer.io -->
816
<script type="text/javascript">
917
var _cio = _cio || [];
@@ -21,13 +29,5 @@
2129
})();
2230
</script>
2331
<!-- Script for sending data to customer.io -->
24-
<style>
25-
body {
26-
background: #142D2B;
27-
}
28-
</style>
29-
</head>
30-
<body>
31-
<div id="root"></div>
3232
</body>
3333
</html>

src/shared/constants/realms.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import frax from "shared/assets/partners/frax.svg"
77
import base from "shared/assets/partners/base.svg"
88
import zksync from "shared/assets/partners/zksync.svg"
99
import { RealmPosition } from "shared/types/realm"
10+
import CHALLENGES_DATA from "assets/challenges-data.json"
1011
import {
1112
realm4,
1213
realm7,
@@ -17,7 +18,6 @@ import {
1718
realm22,
1819
// realm15,
1920
} from "./realms-data"
20-
import CHALLENGES_DATA from "../../assets/challenges-data.json"
2121

2222
// TODO: read the correct challenge data for realms
2323
// The challenge data should be read from a JSON file.

src/shared/context/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./island"
2+
export * from "./reflect"

src/shared/context/island.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint-disable import/prefer-default-export */
2+
import { createContext, MutableRefObject } from "react"
3+
import { IslandContextType } from "shared/types"
4+
5+
export const IslandContext = createContext<MutableRefObject<IslandContextType>>(
6+
{
7+
current: {
8+
onRealmClick: () => {},
9+
},
10+
}
11+
)

src/shared/context/reflect.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* eslint-disable import/prefer-default-export */
2+
import { createContext } from "react"
3+
import { ReflectInstance } from "shared/utils"
4+
5+
export const ReflectContext = createContext<ReflectInstance | null>(null)

src/shared/hooks/assistant.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import { useEffect } from "react"
22
import { LOCAL_STORAGE_ASSISTANT } from "shared/constants"
33
import { selectStakingRealmId, useDappSelector } from "redux-state"
4-
import { useLocalStorageChange } from "./helpers"
5-
6-
type AssistantType = "welcome" | "challenges" | "default" | "first-realm"
7-
8-
type Assistant = {
9-
type: AssistantType
10-
visible: boolean
11-
}
4+
import { Assistant, AssistantType } from "shared/types"
5+
import { useLocalStorageChange } from "./storage"
126

137
// eslint-disable-next-line import/prefer-default-export
148
export function useAssistant(): {

src/shared/hooks/challenge.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { useCallback } from "react"
33
import { LOCAL_STORAGE_DISPLAYED_CHALLENGES } from "shared/constants"
44
import { getRealmIdFromChallengeInLocalStorage } from "shared/utils"
5-
import { useLocalStorageChange } from "./helpers"
5+
import { useLocalStorageChange } from "./storage"
66

77
export function useDisplayedChallenges(): {
88
isChallengeDisplayed: (id: string) => string | false

0 commit comments

Comments
 (0)