Skip to content

Commit 3cce177

Browse files
committed
Use Rspack naming for WebAssembly assets
1 parent 9da5831 commit 3cce177

4 files changed

Lines changed: 30 additions & 34 deletions

File tree

src/config/makeRspackConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export default function makeRspackConfig({
198198
},
199199
output: {
200200
filename: '[name].bundle.js',
201+
webassemblyModuleFilename: '[hash].bundle.wasm',
201202
path: outputPath,
202203
},
203204
externals: ({ request }, callback) =>

src/utils/build.utils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,16 @@ const BuildUtils = {
332332
throwIfAborted(options.signal)
333333
const gzip = gzipSync(bundleContents, {}).length
334334
const matches = asset.name.match(/(.+?)\.bundle\.(.+)$/)
335-
const parsedAssetName = path.parse(asset.name)
336-
const entryName = matches?.[1] || parsedAssetName.name
337-
const extension = matches?.[2] || parsedAssetName.ext.slice(1) || 'asset'
335+
336+
if (!matches) {
337+
throw new UnexpectedBuildError(
338+
'Found an asset without the `.bundle` suffix. ' +
339+
'A loader customization might be needed to recognize this asset type' +
340+
asset.name,
341+
)
342+
}
343+
344+
const [, entryName, extension] = matches
338345

339346
return {
340347
name: entryName,

tests/fast/build.utils.test.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { afterEach, describe, expect, test, vi } from 'vitest'
2-
import fs from 'node:fs'
32
import { BuildCancelledError } from '../../src/errors/CustomError'
43

54
const mockRspack = vi.fn()
@@ -16,8 +15,6 @@ vi.mock('../../src/config/makeRspackConfig.js', () => ({
1615
vi.mock('../../src/utils/telemetry.utils.js', () => ({
1716
default: {
1817
compilePackage: mockCompilePackage,
19-
parseWebpackStats: vi.fn(),
20-
assetsGZIPParseTime: vi.fn(),
2118
},
2219
}))
2320

@@ -216,32 +213,4 @@ describe('BuildUtils.buildPackage', () => {
216213
missingModules: ['missing-package'],
217214
})
218215
})
219-
220-
test('preserves emitted assets that do not use the bundle filename pattern', async () => {
221-
const stats = {
222-
compilation: { errors: [] },
223-
toJson: () => ({
224-
assets: [
225-
{ name: 'main.bundle.js', size: 100, chunkNames: ['main'] },
226-
{ name: 'assets/module.wasm', size: 50, chunkNames: [] },
227-
],
228-
}),
229-
}
230-
231-
vi.spyOn(BuildUtils, 'createEntryPoint').mockReturnValue('/tmp/index.js')
232-
vi.spyOn(BuildUtils, 'compilePackage').mockResolvedValue({
233-
error: null,
234-
stats: stats as any,
235-
})
236-
vi.spyOn(fs.promises, 'readFile').mockResolvedValue(
237-
Buffer.from('asset contents'),
238-
)
239-
240-
await expect(BuildUtils.buildPackage(buildArgs)).resolves.toMatchObject({
241-
assets: [
242-
{ name: 'main', type: 'js', size: 100 },
243-
{ name: 'module', type: 'wasm', size: 50 },
244-
],
245-
})
246-
})
247216
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, test } from 'vitest'
2+
3+
import makeRspackConfig from '../../src/config/makeRspackConfig.js'
4+
5+
describe('makeRspackConfig', () => {
6+
test('uses the bundle filename convention for WebAssembly modules', () => {
7+
const config = makeRspackConfig({
8+
packageName: 'fixture',
9+
entry: '/tmp/index.js',
10+
externals: {
11+
externalPackages: [],
12+
externalBuiltIns: [],
13+
},
14+
outputPath: '/tmp/output',
15+
})
16+
17+
expect(config.output?.webassemblyModuleFilename).toBe('[hash].bundle.wasm')
18+
})
19+
})

0 commit comments

Comments
 (0)