Skip to content

Commit

Permalink
fix(core): output.assetsInclude adds a rule but not exposes public …
Browse files Browse the repository at this point in the history
…api (#4385)
  • Loading branch information
SoonIter authored Jan 20, 2025
1 parent 59709ef commit 4f9650e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/configChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export const CHAIN_ID = {
IMAGE: 'image',
/** Rule for media */
MEDIA: 'media',
/** Rule for additional assets */
ADDITIONAL_ASSETS: 'additional-assets',
/** Rule for js */
JS: 'js',
/** Rule for data uri encoded javascript */
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/plugins/asset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path';
import type { GeneratorOptionsByModuleType } from '@rspack/core';
import { CHAIN_ID } from '../configChain';
import {
AUDIO_EXTENSIONS,
FONT_EXTENSIONS,
Expand Down Expand Up @@ -109,17 +110,17 @@ export const pluginAsset = (): RsbuildPlugin => ({
const { emitAssets } = config.output;

// image
createAssetRule('image', IMAGE_EXTENSIONS, emitAssets);
createAssetRule(CHAIN_ID.RULE.IMAGE, IMAGE_EXTENSIONS, emitAssets);
// svg
createAssetRule('svg', ['svg'], emitAssets);
createAssetRule(CHAIN_ID.RULE.SVG, ['svg'], emitAssets);
// media
createAssetRule(
'media',
CHAIN_ID.RULE.MEDIA,
[...VIDEO_EXTENSIONS, ...AUDIO_EXTENSIONS],
emitAssets,
);
// font
createAssetRule('font', FONT_EXTENSIONS, emitAssets);
createAssetRule(CHAIN_ID.RULE.FONT, FONT_EXTENSIONS, emitAssets);
// assets
const assetsFilename = getMergedFilename('assets');
chain.output.assetModuleFilename(assetsFilename);
Expand All @@ -131,7 +132,9 @@ export const pluginAsset = (): RsbuildPlugin => ({
const { assetsInclude } = config.source;
if (assetsInclude) {
const { dataUriLimit } = config.output;
const rule = chain.module.rule('additional-assets').test(assetsInclude);
const rule = chain.module
.rule(CHAIN_ID.RULE.ADDITIONAL_ASSETS)
.test(assetsInclude);
const maxSize =
typeof dataUriLimit === 'number' ? dataUriLimit : dataUriLimit.assets;

Expand All @@ -140,7 +143,7 @@ export const pluginAsset = (): RsbuildPlugin => ({
rule,
maxSize,
filename: assetsFilename,
assetType: 'additional',
assetType: 'additional-assets',
});
}
});
Expand Down

1 comment on commit 4f9650e

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
plugins ✅ success
rspress ✅ success
rslib ✅ success
examples ✅ success

Please sign in to comment.