From c7e263d91f3b2e67aab5bc7124a8cd59c6175ee8 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 12 Oct 2021 18:00:55 +0800 Subject: [PATCH] chore: remove warnings when minifying css --- packages/uni-cli-shared/src/hbx/log.ts | 9 +++++++++ packages/uni-cli-shared/src/index.ts | 1 + packages/uni-cli-shared/src/logs/format.ts | 20 ++++++++++++++++++- packages/uni-cli-shared/src/logs/index.ts | 2 +- packages/uni-cli-shared/src/mp/event.ts | 20 +++++++++++++++++++ packages/uni-cli-shared/src/mp/index.ts | 1 + packages/uni-stat/dist/uni-stat.cjs.js | 2 +- packages/uni-stat/dist/uni-stat.es.js | 2 +- .../src/configResolved/index.ts | 11 ++++++++-- 9 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 packages/uni-cli-shared/src/mp/event.ts create mode 100644 packages/uni-cli-shared/src/mp/index.ts diff --git a/packages/uni-cli-shared/src/hbx/log.ts b/packages/uni-cli-shared/src/hbx/log.ts index 51c9cd54c..943a4c525 100644 --- a/packages/uni-cli-shared/src/hbx/log.ts +++ b/packages/uni-cli-shared/src/hbx/log.ts @@ -42,3 +42,12 @@ export const removeInfoFormatter: Formatter = { return '' }, } +const REMOVED_WARN_MSGS = ['warnings when minifying css:'] +export const removeWarnFormatter: Formatter = { + test(msg) { + return !!REMOVED_WARN_MSGS.find((m) => msg.includes(m)) + }, + format() { + return '' + }, +} diff --git a/packages/uni-cli-shared/src/index.ts b/packages/uni-cli-shared/src/index.ts index 40f25c5db..0a5e100d6 100644 --- a/packages/uni-cli-shared/src/index.ts +++ b/packages/uni-cli-shared/src/index.ts @@ -1,4 +1,5 @@ export * from './fs' +export * from './mp' export * from './env' export * from './hbx' export * from './logs' diff --git a/packages/uni-cli-shared/src/logs/format.ts b/packages/uni-cli-shared/src/logs/format.ts index df3fbcb91..ca0aa08bd 100644 --- a/packages/uni-cli-shared/src/logs/format.ts +++ b/packages/uni-cli-shared/src/logs/format.ts @@ -2,7 +2,11 @@ import { once } from '@dcloudio/uni-shared' import { isInHBuilderX } from '../hbx/env' import { moduleAliasFormatter } from '../hbx/alias' -import { h5ServeFormatter, removeInfoFormatter } from '../hbx/log' +import { + h5ServeFormatter, + removeInfoFormatter, + removeWarnFormatter, +} from '../hbx/log' export interface Formatter { test: (msg: string) => boolean @@ -11,6 +15,7 @@ export interface Formatter { const errFormatters: Formatter[] = [] const infoFormatters: Formatter[] = [] +const warnFormatters: Formatter[] = [] const initErrFormattersOnce = once(() => { if (isInHBuilderX()) { @@ -31,6 +36,10 @@ const initInfoFormattersOnce = once(() => { infoFormatters.push(removeInfoFormatter) }) +const initWarnFormattersOnce = once(() => { + warnFormatters.push(removeWarnFormatter) +}) + export function formatErrMsg(msg: string) { initErrFormattersOnce() const formatter = errFormatters.find(({ test }) => test(msg)) @@ -48,3 +57,12 @@ export function formatInfoMsg(msg: string) { } return msg } + +export function formatWarnMsg(msg: string) { + initWarnFormattersOnce() + const formatter = warnFormatters.find(({ test }) => test(msg)) + if (formatter) { + return formatter.format(msg) + } + return msg +} diff --git a/packages/uni-cli-shared/src/logs/index.ts b/packages/uni-cli-shared/src/logs/index.ts index 530a3217e..d6b72384f 100644 --- a/packages/uni-cli-shared/src/logs/index.ts +++ b/packages/uni-cli-shared/src/logs/index.ts @@ -1 +1 @@ -export { formatErrMsg, formatInfoMsg } from './format' +export { formatErrMsg, formatInfoMsg, formatWarnMsg } from './format' diff --git a/packages/uni-cli-shared/src/mp/event.ts b/packages/uni-cli-shared/src/mp/event.ts new file mode 100644 index 000000000..6a6ee5af0 --- /dev/null +++ b/packages/uni-cli-shared/src/mp/event.ts @@ -0,0 +1,20 @@ +export function formatMiniProgramEvent( + eventName: string, + { + isCatch, + isCapture, + }: { + isCatch?: boolean + isCapture?: boolean + } +) { + let eventType = 'bind' + if (isCatch) { + eventType = 'catch' + } + if (isCapture) { + return `capture-${eventType}:${eventName}` + } + // 原生组件不支持 bind:input 等写法,统一使用 bindinput + return `${eventType}${eventName}` +} diff --git a/packages/uni-cli-shared/src/mp/index.ts b/packages/uni-cli-shared/src/mp/index.ts new file mode 100644 index 000000000..c475080bb --- /dev/null +++ b/packages/uni-cli-shared/src/mp/index.ts @@ -0,0 +1 @@ +export * from './event' diff --git a/packages/uni-stat/dist/uni-stat.cjs.js b/packages/uni-stat/dist/uni-stat.cjs.js index 21b68a2dd..f6f27a002 100644 --- a/packages/uni-stat/dist/uni-stat.cjs.js +++ b/packages/uni-stat/dist/uni-stat.cjs.js @@ -1,6 +1,6 @@ 'use strict'; -var version = "3.0.0-alpha-3021020210930001"; +var version = "3.0.0-alpha-3021020211012003"; const STAT_VERSION = version; const STAT_URL = 'https://tongji.dcloud.io/uni/stat'; diff --git a/packages/uni-stat/dist/uni-stat.es.js b/packages/uni-stat/dist/uni-stat.es.js index 92618b755..2efce242d 100644 --- a/packages/uni-stat/dist/uni-stat.es.js +++ b/packages/uni-stat/dist/uni-stat.es.js @@ -1,4 +1,4 @@ -var version = "3.0.0-alpha-3021020210930001"; +var version = "3.0.0-alpha-3021020211012003"; const STAT_VERSION = version; const STAT_URL = 'https://tongji.dcloud.io/uni/stat'; diff --git a/packages/vite-plugin-uni/src/configResolved/index.ts b/packages/vite-plugin-uni/src/configResolved/index.ts index c701de8f4..721994e35 100644 --- a/packages/vite-plugin-uni/src/configResolved/index.ts +++ b/packages/vite-plugin-uni/src/configResolved/index.ts @@ -1,9 +1,10 @@ import { Plugin, ResolvedConfig } from 'vite' import { - formatErrMsg, checkUpdate, isWindows, + formatErrMsg, formatInfoMsg, + formatWarnMsg, } from '@dcloudio/uni-cli-shared' import { VitePluginUniResolvedOptions } from '..' @@ -42,13 +43,19 @@ function initCheckUpdate() { } function initLogger({ logger }: ResolvedConfig) { - const { info, error } = logger + const { info, warn, error } = logger logger.info = (msg, opts) => { msg = formatInfoMsg(msg) if (msg) { return info(msg, opts) } } + logger.warn = (msg, opts) => { + msg = formatWarnMsg(msg) + if (msg) { + return warn(msg, opts) + } + } logger.error = (msg, opts) => { msg = formatErrMsg(msg) if (msg) { -- GitLab