Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changeset/better-wombats-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

---
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"lint-staged": "^16.2.7",
"sort-package-json": "^3.6.1",
"ts-patch": "^3.3.0",
"turbo": "^2.8.10",
"turbo": "^2.9.3",
"typescript": "^5.9.3",
"typescript-eslint": "^8.56.0",
"vitest": "^3.2.4"
Expand Down
25 changes: 18 additions & 7 deletions packages/rspeedy/plugin-react/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2029,14 +2029,19 @@ describe('Config', () => {
// Production build with typical macro definitions
vi.stubEnv('NODE_ENV', 'production')

const entryName = 'defineDCE'
const rsbuild = await createRspeedy({
rspeedyConfig: {
source: {
entry: {
main: new URL('./fixtures/defineDCE/macros.js', import.meta.url)
.pathname,
[entryName]:
new URL('./fixtures/defineDCE/macros.js', import.meta.url)
.pathname,
},
},
output: {
cleanDistPath: false,
},
environments: {
lynx: {},
},
Expand All @@ -2060,7 +2065,8 @@ describe('Config', () => {

const distPath = path.join(
rsbuild.context.distPath,
'.rspeedy/main',
'.rspeedy',
entryName,
'main-thread.js',
)

Expand All @@ -2078,16 +2084,19 @@ describe('Config', () => {

vi.stubEnv('NODE_ENV', 'production')

const entryName = 'pure-funcs'
const rsbuild = await createRspeedy({
rspeedyConfig: {
source: {
entry: {
main: new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
.pathname,
[entryName]:
new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
.pathname,
},
},
output: {
filenameHash: false,
cleanDistPath: false,
minify: {
js: true,
jsOptions: {
Expand Down Expand Up @@ -2128,12 +2137,14 @@ describe('Config', () => {

const mainThreadPath = path.join(
rsbuild.context.distPath,
'.rspeedy/main',
'.rspeedy',
entryName,
'main-thread.js',
)
const backgroundPath = path.join(
rsbuild.context.distPath,
'.rspeedy/main',
'.rspeedy',
entryName,
'background.js',
)

Expand Down
45 changes: 29 additions & 16 deletions packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { RspeedyInstance } from '@lynx-js/rspeedy'

import { createStubRspeedy as createRspeedy } from './createRspeedy.js'

async function getCode(rsbuild: RspeedyInstance) {
async function getCode(rsbuild: RspeedyInstance, entryName: string) {
try {
await rsbuild.build()
} catch (_error) {
Expand All @@ -19,12 +19,14 @@ async function getCode(rsbuild: RspeedyInstance) {

const mainThreadPath = path.join(
rsbuild.context.distPath,
'.rspeedy/main',
'.rspeedy',
entryName,
'main-thread.js',
)
const backgroundPath = path.join(
rsbuild.context.distPath,
'.rspeedy/main',
'.rspeedy',
entryName,
'background.js',
)

Expand All @@ -40,19 +42,22 @@ describe('optimizeBundleSize', () => {
test('basic usage', async () => {
const { pluginReactLynx } = await import('../src/pluginReactLynx.js')
vi.stubEnv('NODE_ENV', 'production')
const entryName = 'optimizeBundleSize-0'
const rsbuild = await createRspeedy({
rspeedyConfig: {
source: {
entry: {
main: new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
.pathname,
[entryName]:
new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
.pathname,
},
},
output: {
filenameHash: false,
minify: {
js: true,
},
cleanDistPath: false,
},
environments: {
lynx: {},
Expand All @@ -65,7 +70,7 @@ describe('optimizeBundleSize', () => {

const [config] = await rsbuild.initConfigs()
expect(config?.optimization?.minimizer).toMatchSnapshot()
const { mainThreadCode, backgroundCode } = await getCode(rsbuild)
const { mainThreadCode, backgroundCode } = await getCode(rsbuild, entryName)

expect(mainThreadCode).not.toContain('background-only')
expect(mainThreadCode).toContain('main-thread-only')
Expand All @@ -82,16 +87,19 @@ describe('optimizeBundleSize', () => {
const { pluginReactLynx } = await import('../src/pluginReactLynx.js')
vi.stubEnv('NODE_ENV', 'production')

const entryName = 'optimizeBundleSize-1'
const rsbuild = await createRspeedy({
rspeedyConfig: {
source: {
entry: {
main: new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
.pathname,
[entryName]:
new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
.pathname,
},
},
output: {
filenameHash: false,
cleanDistPath: false,
minify: {
js: true,
jsOptions: {
Expand All @@ -117,7 +125,7 @@ describe('optimizeBundleSize', () => {
const [config] = await rsbuild.initConfigs()
expect(config?.optimization?.minimizer).toMatchSnapshot()

const { mainThreadCode, backgroundCode } = await getCode(rsbuild)
const { mainThreadCode, backgroundCode } = await getCode(rsbuild, entryName)
expect(mainThreadCode).toContain('background-only')
expect(mainThreadCode).toContain('main-thread-only')
expect(mainThreadCode).not.toContain('default console.info')
Expand All @@ -132,17 +140,19 @@ describe('optimizeBundleSize', () => {
test('optimize main-thread code', async () => {
const { pluginReactLynx } = await import('../src/pluginReactLynx.js')
vi.stubEnv('NODE_ENV', 'production')

const entryName = 'optimizeBundleSize-2'
const rsbuild = await createRspeedy({
rspeedyConfig: {
source: {
entry: {
main: new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
.pathname,
[entryName]:
new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
.pathname,
},
},
output: {
filenameHash: false,
cleanDistPath: false,
minify: {
js: true,
jsOptions: {
Expand All @@ -165,7 +175,7 @@ describe('optimizeBundleSize', () => {
},
})

const { mainThreadCode, backgroundCode } = await getCode(rsbuild)
const { mainThreadCode, backgroundCode } = await getCode(rsbuild, entryName)

expect(mainThreadCode).not.toContain('background-only')
expect(mainThreadCode).toContain('main-thread-only')
Expand All @@ -182,16 +192,19 @@ describe('optimizeBundleSize', () => {
const { pluginReactLynx } = await import('../src/pluginReactLynx.js')
vi.stubEnv('NODE_ENV', 'production')

const entryName = 'optimizeBundleSize-3'
const rsbuild = await createRspeedy({
rspeedyConfig: {
source: {
entry: {
main: new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
.pathname,
[entryName]:
new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
.pathname,
},
},
output: {
filenameHash: false,
cleanDistPath: false,
minify: {
js: true,
mainThreadOptions: {
Expand Down Expand Up @@ -219,7 +232,7 @@ describe('optimizeBundleSize', () => {
},
})

const { mainThreadCode, backgroundCode } = await getCode(rsbuild)
const { mainThreadCode, backgroundCode } = await getCode(rsbuild, entryName)
expect(mainThreadCode).not.toContain('background-only')
expect(mainThreadCode).toContain('main-thread-only')
expect(mainThreadCode).not.toContain('default console.info')
Expand Down
118 changes: 59 additions & 59 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading