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
5 changes: 3 additions & 2 deletions packages/core/src/asset/LibSvgrPatchPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type Rspack, rspack } from '@rsbuild/core';
import { getUndoPath } from '../css/utils';
import { getAssetNames } from '../utils/compilation';

const pluginName = 'LIB_SVGR_PATCH_PLUGIN';

Expand All @@ -9,9 +10,9 @@ export class LibSvgrPatchPlugin implements Rspack.RspackPluginInstance {
readonly name: string = pluginName;
apply(compiler: Rspack.Compiler): void {
compiler.hooks.make.tap(this.name, (compilation) => {
compilation.hooks.processAssets.tap(this.name, (assets) => {
compilation.hooks.processAssets.tap(this.name, () => {
const isEsm = Boolean(compilation.options.output.module);
const chunkAsset = Object.keys(assets).filter((name) =>
const chunkAsset = getAssetNames(compilation).filter((name) =>
name.endsWith('js'),
);
for (const name of chunkAsset) {
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/css/LibCssExtractPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Rspack, rspack } from '@rsbuild/core';
import { getAssetNames } from '../utils/compilation';
import {
ABSOLUTE_PUBLIC_PATH,
AUTO_PUBLIC_PATH,
Expand Down Expand Up @@ -26,8 +27,8 @@ class LibCssExtractPlugin implements Rspack.RspackPluginInstance {
* replace publicPath placeholders of miniCssExtractLoader
*/
compiler.hooks.make.tap(pluginName, (compilation) => {
compilation.hooks.processAssets.tap(pluginName, (assets) => {
const chunkAsset = Object.keys(assets).filter((name) =>
compilation.hooks.processAssets.tap(pluginName, () => {
const chunkAsset = getAssetNames(compilation).filter((name) =>
name.includes('.css'),
);
for (const name of chunkAsset) {
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/css/cssConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { EnvironmentConfig, RsbuildPlugin } from '@rsbuild/core';
import { createRequire } from 'node:module';
import { getAssetNames } from '../utils/compilation';
import { LibCssExtractPlugin } from './LibCssExtractPlugin';
import {
type CssLoaderOptionsAuto,
Expand Down Expand Up @@ -97,8 +98,8 @@ const pluginLibCss = (
// 2. preserve CSS Modules asset
api.processAssets(
{ stage: 'additional' }, // deleteAsset as soon as possible for small perf
({ assets, compilation }) => {
for (const key of Object.keys(assets)) {
({ compilation }) => {
for (const key of getAssetNames(compilation)) {
if (RegExp(RSLIB_CSS_ENTRY_FLAG).exec(key)) {
compilation.deleteAsset(key);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/plugins/ChunkAssetPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type EnvironmentConfig, type Rspack, rspack } from '@rsbuild/core';
import { JS_EXTENSIONS_PATTERN } from '../constant';
import type { DeepRequired, Format, Shims } from '../types';
import { getAssetNames } from '../utils/compilation';

const PLUGIN_NAME = 'rsbuild:lib-chunk-asset';
const IMPORT_META_URL_SHIM = `const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
Expand Down Expand Up @@ -68,8 +69,8 @@ class ChunkAssetPlugin {
});

// The default stage runs before minification, which can remove unused shims.
compilation.hooks.processAssets.tap(PLUGIN_NAME, (assets) => {
const chunkAsset = Object.keys(assets).filter((name) => {
compilation.hooks.processAssets.tap(PLUGIN_NAME, () => {
const chunkAsset = getAssetNames(compilation).filter((name) => {
return (
JS_EXTENSIONS_PATTERN.test(name) && jsChunkAssetNames.has(name)
);
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/utils/compilation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Rspack } from '@rsbuild/core';

export function getAssetNames(compilation: Rspack.Compilation): string[] {
// The assets Proxy uses this method for ownKeys. Calling it directly avoids
// Proxy key validation and the per-asset descriptor lookups in Object.keys.
return compilation.__internal__getAssetFilenames();
}
Loading