@@ -19,37 +19,47 @@ export default (api: IApi) => {
1919 throw new Error ( 'removeConsole does not support uglifyJs' )
2020 }
2121 if ( api . appData . bundler === 'webpack' && userConfig . jsMinifier === 'swc' ) {
22- throw new Error ( 'removeConsole does not support using swc compression in webpack mode' )
22+ throw new Error (
23+ 'removeConsole does not support using swc compression in webpack mode' ,
24+ )
2325 }
2426 } )
2527
2628 api . modifyConfig ( ( memo ) => {
2729 const { removeConsole } = memo
28- const isRspack = api . appData . bundler === 'rspack'
29- // Default is esbuild
30- const jsMinifier =
31- api . appData . bundler === 'rspack'
32- ? api . userConfig . jsMinifier || 'swc'
33- : api . userConfig . jsMinifier || 'esbuild'
34-
35- const compressOptions = Array . isArray ( removeConsole )
36- ? { pure_funcs : removeConsole . map ( ( method ) => `console.${ method } ` ) }
37- : { drop_console : true }
30+ // Fix: Check for rspack config instead of bundler name
31+ const isRspack = ! ! memo . rspack || ! ! api . userConfig . rspack
32+ // Default is esbuild for webpack, swc for rspack
33+ const jsMinifier = isRspack
34+ ? api . userConfig . jsMinifier || 'swc'
35+ : api . userConfig . jsMinifier || 'esbuild'
3836
3937 if ( isRspack && jsMinifier === 'swc' ) {
38+ // SWC configuration issue: drop_console doesn't work in current Rspack version
39+ // Workaround: Automatically switch to terser when removeConsole is enabled
40+
41+ // Force switch to terser for removeConsole functionality
42+ memo . jsMinifier = 'terser'
43+
44+ // Apply terser configuration
45+ const compressOptions = Array . isArray ( removeConsole )
46+ ? { pure_funcs : removeConsole . map ( ( method ) => `console.${ method } ` ) }
47+ : { drop_console : true }
48+
4049 memo . jsMinifierOptions = {
4150 ...memo . jsMinifierOptions ,
42- minimizerOptions : {
43- ...memo . jsMinifierOptions ?. minimizerOptions ,
44- compress : {
45- ...memo . jsMinifierOptions ?. minimizerOptions ?. compress ,
46- ...compressOptions ,
47- } ,
51+ compress : {
52+ ...memo . jsMinifierOptions ?. compress ,
53+ ...compressOptions ,
4854 } ,
4955 }
5056 return memo
5157 }
5258
59+ const compressOptions = Array . isArray ( removeConsole )
60+ ? { pure_funcs : removeConsole . map ( ( method ) => `console.${ method } ` ) }
61+ : { drop_console : true }
62+
5363 // esbuild
5464 if ( jsMinifier === 'esbuild' ) {
5565 const compressOptions = Array . isArray ( removeConsole )
0 commit comments