Commit 337adcc 1 parent bf9a0fc commit 337adcc Copy full SHA for 337adcc
File tree 2 files changed +30
-3
lines changed
e2e/cases/plugin-api/plugin-process-assets-by-environments
2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { existsSync } from 'node:fs';
2
2
import { join } from 'node:path' ;
3
3
import { build , rspackOnlyTest } from '@e2e/helper' ;
4
4
import { expect } from '@playwright/test' ;
5
+ import type { RsbuildPluginAPI } from '@rsbuild/core' ;
5
6
6
7
rspackOnlyTest (
7
8
'should allow plugin to process assets by environments' ,
@@ -14,3 +15,29 @@ rspackOnlyTest(
14
15
expect ( existsSync ( join ( rsbuild . distPath , 'server/index.js' ) ) ) . toBeTruthy ( ) ;
15
16
} ,
16
17
) ;
18
+
19
+ rspackOnlyTest ( 'should filter environments correctly' , async ( ) => {
20
+ const rsbuild = await build ( {
21
+ cwd : __dirname ,
22
+ plugins : [
23
+ {
24
+ name : 'my-plugin-node' ,
25
+ setup ( api : RsbuildPluginAPI ) {
26
+ api . processAssets (
27
+ { stage : 'summarize' , environments : [ 'node' ] } ,
28
+ ( { assets, compilation } ) => {
29
+ for ( const key of Object . keys ( assets ) ) {
30
+ if ( key . endsWith ( '.js' ) ) {
31
+ compilation . deleteAsset ( key ) ;
32
+ }
33
+ }
34
+ } ,
35
+ ) ;
36
+ } ,
37
+ } ,
38
+ ] ,
39
+ } ) ;
40
+
41
+ expect ( existsSync ( join ( rsbuild . distPath , 'static/index.js' ) ) ) . toBeFalsy ( ) ;
42
+ expect ( existsSync ( join ( rsbuild . distPath , 'server/index.js' ) ) ) . toBeFalsy ( ) ;
43
+ } ) ;
Original file line number Diff line number Diff line change @@ -179,7 +179,7 @@ export function initPluginAPI({
179
179
pluginEnvironment &&
180
180
! isPluginMatchEnvironment ( pluginEnvironment , environment . name )
181
181
) {
182
- return ;
182
+ continue ;
183
183
}
184
184
185
185
compiler . hooks . compilation . tap (
@@ -213,7 +213,7 @@ export function initPluginAPI({
213
213
} of processAssetsFns ) {
214
214
// filter by targets
215
215
if ( descriptor . targets && ! descriptor . targets . includes ( target ) ) {
216
- return ;
216
+ continue ;
217
217
}
218
218
219
219
// filter by environments
@@ -224,7 +224,7 @@ export function initPluginAPI({
224
224
( pluginEnvironment &&
225
225
! isPluginMatchEnvironment ( pluginEnvironment , environment . name ) )
226
226
) {
227
- return ;
227
+ continue ;
228
228
}
229
229
230
230
compilation . hooks . processAssets . tapPromise (
You can’t perform that action at this time.
0 commit comments