Skip to content

Commit 514ff8d

Browse files
committed
feat: add rsbuild
1 parent 114735a commit 514ff8d

File tree

9 files changed

+459
-826
lines changed

9 files changed

+459
-826
lines changed

package.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"@vkontakte/vk-bridge-react": "^1.0.0",
2424
"@vkontakte/vk-mini-apps-router": "1.4.2",
2525
"@vkontakte/vkui": "6.0.0",
26-
"jshashes": "^1.0.8",
2726
"preact": "^10.19.3",
2827
"react": "npm:@preact/compat",
2928
"react-dom": "npm:@preact/compat"
@@ -33,22 +32,18 @@
3332
"react-dom": "^18.2.0"
3433
},
3534
"devDependencies": {
36-
"@babel/eslint-parser": "^7.23.3",
3735
"@biomejs/biome": "1.5.2",
3836
"@diary-spo/shared": "1.8.9",
3937
"@diary-spo/types": "latest",
40-
"@preact/preset-vite": "^2.8.1",
41-
"@rollup/plugin-terser": "^0.4.4",
4238
"@rsbuild/core": "^0.3.6",
39+
"@rsbuild/plugin-image-compress": "^0.3.7",
4340
"@rsbuild/plugin-react": "^0.3.6",
4441
"@types/node": "^20.11.5",
4542
"@vitest/coverage-v8": "^1.2.1",
4643
"@vkontakte/vk-miniapps-deploy": "^0.1.6",
47-
"dotenv": "^16.3.2",
4844
"gh-pages": "^6.0.0",
4945
"jsdom": "^23.2.0",
5046
"typescript": "^5.2.2",
51-
"vite": "5.0.12",
5247
"vitest": "^1.2.1",
5348
"vitest-localstorage-mock": "^0.0.1"
5449
}

rsbuild.config.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
import { pluginReact } from '@rsbuild/plugin-react';
1+
import { loadEnv } from '@rsbuild/core'
2+
import { pluginImageCompress } from '@rsbuild/plugin-image-compress'
3+
import { pluginReact } from '@rsbuild/plugin-react'
4+
5+
const { publicVars } = loadEnv()
26

37
export default {
4-
plugins: [pluginReact()],
5-
html: {
6-
template: './index.html',
8+
performance: {
9+
removeMomentLocale: true,
10+
chunkSplit: {
11+
strategy: 'split-by-experience'
12+
}
713
},
8-
9-
};
14+
output: {
15+
polyfill: 'usage'
16+
},
17+
analyzerMode: 'static',
18+
openAnalyzer: false,
19+
reportFilename: 'report-web.html',
20+
source: {
21+
define: publicVars
22+
},
23+
plugins: [pluginReact(), pluginImageCompress()],
24+
html: {
25+
template: './index.html'
26+
}
27+
}

src/config/env.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import 'dotenv/config'
2-
export const BASE_URL = process.env.VITE_SERVER_URL
3-
export const SECOND_SERVER_URL = process.env.VITE_SERVER_URL_SECOND
4-
console.log(process.env.BAR); // '1'
5-
export const MODE = process.env.VITE_MODE
1+
export const BASE_URL = process.env.PUBLIC_SERVER_URL
2+
export const SECOND_SERVER_URL = process.env.PUBLIC_SERVER_URL_SECOND
3+
export const MODE = process.env.PUBLIC_MODE
64

75
export const Mode = {
86
DEV: 'dev',

src/libs/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './jshashes.ts'

src/libs/jshashes.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const generateSHA256Hash = async (input: string): Promise<string> => {
2+
const encoder = new TextEncoder()
3+
const data = encoder.encode(input)
4+
5+
const buffer = await crypto.subtle.digest('SHA-256', data)
6+
7+
const arrayBuffer = new Uint8Array(buffer)
8+
return Array.from(arrayBuffer)
9+
.map((byte) => String.fromCharCode(byte))
10+
.join('')
11+
}
12+
13+
export const Hashes = {
14+
SHA256: {
15+
b64: async (input: string): Promise<string> => {
16+
const sha256Hash = await generateSHA256Hash(input)
17+
return btoa(sha256Hash)
18+
}
19+
}
20+
}

src/views/LoginForm.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import {
1515
Input,
1616
Panel
1717
} from '@vkontakte/vkui'
18-
import Hashes from 'jshashes'
1918
import { ChangeEvent, FC } from 'preact/compat'
2019
import { useEffect, useState } from 'preact/hooks'
2120
import { useSnackbar } from '../hooks'
21+
import { Hashes } from '../libs'
2222
import { makeRequest } from '../methods'
2323
import { VIEW_SCHEDULE } from '../routes'
2424
import { loginPattern } from '../types'
@@ -70,15 +70,16 @@ const LoginForm: FC<{ id: string }> = ({ id }) => {
7070
return
7171
}
7272

73-
const passwordHashed = new Hashes.SHA256().b64(password)
73+
const passwordHashed2 = await Hashes.SHA256.b64(password)
7474

75+
console.error('passwordHashed2', passwordHashed2)
7576
setIsLoading(true)
7677
const response = await makeRequest<ResponseLogin>(
7778
'/login/',
7879
'POST',
7980
JSON.stringify({
8081
login,
81-
password: passwordHashed,
82+
password: passwordHashed2,
8283
isHash: true
8384
})
8485
)

src/views/TechWorking.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// import { AppRoot, Button, Div } from '@vkontakte/vkui'
2-
// import { notFoundStyle, text } from '../views/index.tsx'
2+
// import { notFoundStyle, text } from '../views/index.ts'
33
//
44
// const TechWorking = () => {
55
// return (

vite.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default defineConfig({
3939
safari10: false
4040
},
4141
rollupOptions: {
42-
logLevel: 'debug',
42+
logLevel: 'debug'
4343
}
4444
}
4545
})

0 commit comments

Comments
 (0)