-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to custom manifest JSON (#4289)
- Loading branch information
1 parent
9d922d0
commit 3b6594d
Showing
4 changed files
with
181 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { build, dev } from '@e2e/helper'; | ||
import { expect, test } from '@playwright/test'; | ||
import type { RsbuildConfig } from '@rsbuild/core'; | ||
|
||
const fixtures = __dirname; | ||
|
||
const rsbuildConfig: RsbuildConfig = { | ||
output: { | ||
manifest: { | ||
filename: 'my-manifest.json', | ||
generate: ({ files, manifestData }) => { | ||
return { | ||
filesCount: files.length, | ||
data: manifestData, | ||
}; | ||
}, | ||
}, | ||
legalComments: 'none', | ||
sourceMap: false, | ||
filenameHash: false, | ||
}, | ||
performance: { | ||
chunkSplit: { | ||
strategy: 'all-in-one', | ||
}, | ||
}, | ||
}; | ||
|
||
test('should allow to custom generate manifest data in production build', async () => { | ||
const rsbuild = await build({ | ||
cwd: fixtures, | ||
rsbuildConfig, | ||
}); | ||
|
||
const files = await rsbuild.unwrapOutputJSON(); | ||
const manifestContent = | ||
files[ | ||
Object.keys(files).find((file) => file.endsWith('my-manifest.json'))! | ||
]; | ||
const manifest = JSON.parse(manifestContent); | ||
|
||
expect(manifest.filesCount).toBe(2); | ||
expect(manifest.data.allFiles.length).toBe(2); | ||
expect(manifest.data.entries.index).toMatchObject({ | ||
initial: { | ||
js: ['/static/js/index.js'], | ||
}, | ||
html: ['/index.html'], | ||
}); | ||
}); | ||
|
||
test('should allow to custom generate manifest data in dev', async ({ | ||
page, | ||
}) => { | ||
const rsbuild = await dev({ | ||
cwd: fixtures, | ||
page, | ||
rsbuildConfig, | ||
}); | ||
|
||
const files = await rsbuild.unwrapOutputJSON(); | ||
const manifestContent = | ||
files[ | ||
Object.keys(files).find((file) => file.endsWith('my-manifest.json'))! | ||
]; | ||
const manifest = JSON.parse(manifestContent); | ||
|
||
expect(manifest.filesCount).toBe(2); | ||
expect(manifest.data.allFiles.length).toBe(2); | ||
expect(manifest.data.entries.index).toMatchObject({ | ||
initial: { | ||
js: ['/static/js/index.js'], | ||
}, | ||
html: ['/index.html'], | ||
}); | ||
|
||
await rsbuild.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('hello!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters