File tree 1 file changed +11
-0
lines changed
packages/uni-cli-shared/src/vite/plugins
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -19,13 +19,24 @@ const debugConsole = debug('uni:console')
19
19
export function uniConsolePlugin ( options : ConsoleOptions ) : Plugin {
20
20
const filter = createFilter ( options . include , options . exclude )
21
21
let resolvedConfig : ResolvedConfig
22
+ let dropConsole = false
22
23
return {
23
24
name : 'uni:console' ,
24
25
enforce : 'pre' ,
25
26
configResolved ( config ) {
26
27
resolvedConfig = config
28
+ // 理论上发行模式就不应该有这个逻辑了,只不过为了尽量不引发兼容性问题,目前严谨一些判断是否配置了 drop_console
29
+ if ( process . env . NODE_ENV !== 'development' ) {
30
+ const compressOptions = resolvedConfig . build . terserOptions ?. compress
31
+ if ( compressOptions && typeof compressOptions === 'object' ) {
32
+ dropConsole = ! ! compressOptions . drop_console
33
+ }
34
+ }
27
35
} ,
28
36
transform ( code , id ) {
37
+ if ( dropConsole ) {
38
+ return
39
+ }
29
40
if ( isRenderjs ( id ) || isWxs ( id ) ) {
30
41
return {
31
42
code : restoreConsoleExpr ( code ) ,
You can’t perform that action at this time.
0 commit comments