Skip to content

Commit

Permalink
feat: add new Remote frontend needs to have <30kB minimized impact on…
Browse files Browse the repository at this point in the history
  • Loading branch information
kris liu authored and kris-liu-smile committed Aug 15, 2022
1 parent 0ca507c commit 36d2050
Show file tree
Hide file tree
Showing 8 changed files with 810 additions and 997 deletions.
1 change: 0 additions & 1 deletion apps/storefront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"@rollup/plugin-graphql": "^1.1.0",
"@types/babel__core": "^7.1.19",
"date-fns": "^2.28.0",
"graphql": "^16.5.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-hook-form": "^7.33.1",
Expand Down
67 changes: 37 additions & 30 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
useEffect,
lazy,
Suspense,
} from 'react'
import {
HashRouter,
Expand All @@ -11,12 +13,6 @@ import {
} from '@b3/hooks'
import styled from '@emotion/styled'

import {
Home,
Form,
Registered,
RegisteredBCToB2B,
} from '@/pages'
import {
Layout,
RegisteredCloseButton,
Expand Down Expand Up @@ -45,6 +41,14 @@ const {
overflow: defaultOverflow,
} = document.body.style

const Home = lazy(() => import('./pages/Home'))

const Form = lazy(() => import('./pages/Form'))

const Registered = lazy(() => import('./pages/registered/Registered'))

const RegisteredBCToB2B = lazy(() => import('./pages/registered/RegisteredBCToB2B'))

export default function App() {
const [isOpen, setIsOpen] = useB3AppOpen(false)

Expand All @@ -66,37 +70,40 @@ export default function App() {
fontUrl={FONT_URL}
customStyles={CUSTOM_STYLES}
>

{isOpen ? (
<Layout close={() => setIsOpen(false)}>
<HeaderContainer>
<RegisteredCloseButton setIsOpen={setIsOpen} />
</HeaderContainer>
<Routes>
<Route
path="/"
element={<Home />}
/>
<Route
path="/form"
element={<Form />}
/>
<Route
path="/registered"
element={(
<RegisteredProvider>
<Registered setIsOpen={setIsOpen} />
</RegisteredProvider>
<Suspense fallback={<div>Loading...</div>}>
<Routes>
<Route
path="/"
element={<Home />}
/>
<Route
path="/form"
element={<Form />}
/>
<Route
path="/registered"
element={(
<RegisteredProvider>
<Registered setIsOpen={setIsOpen} />
</RegisteredProvider>
)}
/>
<Route
path="/registeredbctob2b"
element={(
<RegisteredProvider>
<RegisteredBCToB2B />
</RegisteredProvider>
/>
<Route
path="/registeredbctob2b"
element={(
<RegisteredProvider>
<RegisteredBCToB2B />
</RegisteredProvider>
)}
/>
</Routes>
/>
</Routes>
</Suspense>
</Layout>
) : null}
</ThemeFrame>
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
const Variant = 'filled'
const TEST_SITE_KEY = '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'

export function Form() {
export default function Form() {
const [state, setState] = useState<'success'|'error'|'expired'>('error')

return (
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const bull = (
</Box>
)

export function Home() {
export default function Home() {
return (
<Card sx={{
minWidth: 275,
Expand Down
9 changes: 0 additions & 9 deletions apps/storefront/src/pages/index.tsx

This file was deleted.

14 changes: 8 additions & 6 deletions apps/storefront/src/pages/registered/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Registered from './Registered'
import RegisteredBCToB2B from './RegisteredBCToB2B'
// import Registered from './Registered'
// import RegisteredBCToB2B from './RegisteredBCToB2B'

export {
Registered,
RegisteredBCToB2B,
}
// export default {
// Registered,
// RegisteredBCToB2B,
// }

export {}
12 changes: 12 additions & 0 deletions apps/storefront/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,16 @@ export default defineConfig({
),
},
},
build: {
rollupOptions: {
manualChunks: {
mui: ['@mui/material'],
dropzone: ['react-mui-dropzone'],
muiIcon: ['@mui/icons-material'],
muiPickers: ['@mui/x-date-pickers'],
dateFns: ['date-fns'],
lang: ['@b3/lang'],
},
},
},
})
Loading

0 comments on commit 36d2050

Please sign in to comment.