Skip to content

Commit 5d1d45a

Browse files
authored
refactor: optimize bundle size (#555)
1 parent f788488 commit 5d1d45a

58 files changed

Lines changed: 327 additions & 193 deletions

Some content is hidden

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

.github/workflows/publish-all.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Publish Extension to All Stores
22

33
on: [workflow_dispatch]
44

5+
env:
6+
MAX_PACKAGE_SIZE: 2621440 # 2.5MB in bytes
7+
58
jobs:
69
build:
710
runs-on: ubuntu-latest
@@ -25,6 +28,30 @@ jobs:
2528
- name: Build for Firefox
2629
run: npm run build:firefox
2730

31+
- name: Check file sizes
32+
run: |
33+
# Check Chrome/Edge package size
34+
CHROME_SIZE=$(ls -l market_packages/target.zip | awk '{print $5}')
35+
echo "Chrome/Edge package: $CHROME_SIZE bytes"
36+
37+
if [ $CHROME_SIZE -gt $MAX_PACKAGE_SIZE ]; then
38+
echo "❌ Error: Chrome/Edge package exceeds size limit"
39+
exit 1
40+
else
41+
echo "✅ Chrome/Edge package size is within limit"
42+
fi
43+
44+
# Check Firefox package size
45+
FIREFOX_SIZE=$(ls -l market_packages/target.firefox.zip | awk '{print $5}')
46+
echo "Firefox package: $FIREFOX_SIZE bytes"
47+
48+
if [ $FIREFOX_SIZE -gt $MAX_PACKAGE_SIZE ]; then
49+
echo "❌ Error: Firefox package exceeds size limit"
50+
exit 1
51+
else
52+
echo "✅ Firefox package size is within limit"
53+
fi
54+
2855
- name: Upload Chrome/Edge Artifact
2956
uses: actions/upload-artifact@v4
3057
with:

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,11 @@
6969
},
7070
"dependencies": {
7171
"@element-plus/icons-vue": "^2.3.2",
72-
"@vueuse/core": "^13.9.0",
7372
"countup.js": "^2.9.0",
7473
"echarts": "^6.0.0",
7574
"element-plus": "2.11.4",
7675
"js-base64": "^3.7.8",
7776
"punycode": "^2.3.1",
78-
"stream-browserify": "^3.0.0",
7977
"vue": "^3.5.22",
8078
"vue-router": "^4.5.1"
8179
},

rspack/rspack.analyze.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { RsdoctorRspackPlugin } from "@rsdoctor/rspack-plugin"
2-
import path from "path"
3-
import manifest from "../src/manifest"
4-
import optionGenerator from "./rspack.common"
2+
import option from "./rspack.prod"
3+
import { enhancePluginWith } from './util'
54

6-
const outputPath = path.resolve(__dirname, '..', 'dist_prod')
7-
const option = optionGenerator({ outputPath, manifest, mode: "production" })
8-
9-
const { plugins = [] } = option
10-
plugins.push(new RsdoctorRspackPlugin())
11-
option.plugins = plugins
5+
enhancePluginWith(option, new RsdoctorRspackPlugin())
126

137
export default option

rspack/rspack.common.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,15 @@ const staticOptions: Configuration = {
109109
resolve: {
110110
extensions: ['.ts', '.tsx', ".js", '.css', '.scss', '.sass'],
111111
tsConfig: join(__dirname, '..', 'tsconfig.json'),
112-
fallback: {
113-
// fallbacks of axios's dependencies start
114-
stream: require.resolve('stream-browserify'),
115-
zlib: false,
116-
https: false,
117-
http: false,
118-
url: false,
119-
assert: false,
120-
// fallbacks of axios's dependencies end
121-
}
122112
},
123113
optimization: {
124114
splitChunks: {
125115
chunks: chunkFilter,
126116
cacheGroups: {
117+
elementPlus: {
118+
name: 'element-plus',
119+
test: /[\\/]node_modules[\\/]element-plus[\\/]/,
120+
},
127121
defaultVendors: {
128122
filename: 'vendor/[name].js'
129123
}
@@ -191,10 +185,8 @@ const generateOption = ({ outputPath, manifest, mode }: Option) => {
191185
filename: '[name].js',
192186
},
193187
plugins, mode,
194-
}
195-
if (mode === "development") {
196188
// no eval with development, but generate *.map.js
197-
config.devtool = 'cheap-module-source-map'
189+
devtool: mode === 'development' ? 'cheap-module-source-map' : false,
198190
}
199191
return config
200192
}

rspack/rspack.prod.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "path"
22
import manifest from "../src/manifest"
33
import { FileManagerPlugin } from "./plugins/file-manager"
44
import optionGenerator from "./rspack.common"
5+
import { enhancePluginWith } from './util'
56

67
const { name, version } = require(path.join(__dirname, '..', 'package.json'))
78

@@ -33,9 +34,7 @@ const filemanagerPlugin = new FileManagerPlugin({
3334

3435
const option = optionGenerator({ outputPath, manifest, mode: "production" })
3536

36-
const { plugins = [] } = option
37-
plugins.push(filemanagerPlugin)
38-
option.plugins = plugins
37+
enhancePluginWith(option, filemanagerPlugin)
3938
option.devtool = false
4039

4140
export default option

rspack/util.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { type RspackOptions, type RspackPluginInstance } from '@rspack/core'
2+
3+
export function enhancePluginWith(option: RspackOptions, ...toPush: RspackPluginInstance[]) {
4+
const { plugins = [] } = option
5+
plugins.push(...toPush)
6+
option.plugins = plugins
7+
}

script/psl.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
/**
22
* Build psl tree
33
*/
4-
4+
import { fetchGet } from '@api/http'
55
import { type PslTree } from '@util/psl'
6-
import axios from 'axios'
76
import { writeFileSync } from 'fs'
87
import path from 'path'
9-
import punycode from "punycode/"
8+
import punycode from "punycode"
109

1110
const LIST_URL = "https://publicsuffix.org/list/effective_tld_names.dat"
1211
const JSON_PATH = path.join(__dirname, "..", "src", "util", "psl", "rules.json")
1312

1413
const downloadList = async (): Promise<string> => {
15-
const response = await axios.get(LIST_URL)
16-
return response.data
14+
const response = await fetchGet(LIST_URL)
15+
return response.text()
1716
}
1817

1918
const parse = (tree: PslTree, parts: string[], index: number) => {

src/api/chrome/script.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export async function executeScript(tabId: number, files: string[]): Promise<voi
66
try {
77
await chrome.scripting.executeScript({ target: { tabId }, files })
88
} catch {
9+
console.warn(`Failed to execute scrips: ${files}`)
910
}
1011
} else {
1112
await Promise.all(files.map(file => executeScriptMv2(tabId, file)))

src/api/crowdin.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { CROWDIN_PROJECT_ID } from "@util/constant/url"
9-
import axios, { type AxiosResponse } from "axios"
9+
import { fetchGet } from './http'
1010

1111
/**
1212
* Used to obtain translation status
@@ -31,10 +31,8 @@ export async function getTranslationStatus(): Promise<TranslationStatusInfo[]> {
3131
const limit = 500
3232
const auth = `Bearer ${PUBLIC_TOKEN}`
3333
const url = `https://api.crowdin.com/api/v2/projects/${CROWDIN_PROJECT_ID}/languages/progress?limit=${limit}`
34-
const response: AxiosResponse = await axios.get(url, {
35-
headers: { "Authorization": auth }
36-
})
37-
const data: { data: { data: TranslationStatusInfo }[] } = response.data
34+
const response = await fetchGet(url, { headers: { "Authorization": auth } })
35+
const data: { data: { data: TranslationStatusInfo }[] } = await response.json()
3836
return data.data.map(i => i.data)
3937
}
4038

@@ -46,10 +44,8 @@ export async function getMembers(): Promise<MemberInfo[]> {
4644
let offset = 0
4745
while (true) {
4846
const url = `https://api.crowdin.com/api/v2/projects/${CROWDIN_PROJECT_ID}/members?limit=${limit}&offset=${offset}`
49-
const response: AxiosResponse = await axios.get(url, {
50-
headers: { "Authorization": auth }
51-
})
52-
const data: { data: { data: MemberInfo }[] } = response.data
47+
const response = await fetchGet(url, { headers: { "Authorization": auth } })
48+
const data: { data: { data: MemberInfo }[] } = await response.json()
5349
const newItems = data?.data?.map(i => i.data) ?? []
5450
result.push(...newItems)
5551

src/content-script/limit/modal/Main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Alert from "./components/Alert"
33
import Footer from "./components/Footer"
44
import Reason from "./components/Reason"
55
import { provideRule } from "./context"
6-
import "./style"
6+
import "./style/index.sass"
77

88
const _default = defineComponent(() => {
99
provideRule()

0 commit comments

Comments
 (0)