Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): output.assetsInclude adds a rule but not exposes public api #4385

Merged
merged 3 commits into from
Jan 20, 2025
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
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
Loading