From: Evan You Date: Thu, 23 Sep 2021 18:04:52 +0000 (-0400) Subject: chore: improve feature flag warning X-Git-Tag: v3.2.17~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1cf26d2074231de7f17b09484233c61c683fbff;p=thirdparty%2Fvuejs%2Fcore.git chore: improve feature flag warning --- diff --git a/packages/runtime-core/src/featureFlags.ts b/packages/runtime-core/src/featureFlags.ts index ee2f136872..e04c352c57 100644 --- a/packages/runtime-core/src/featureFlags.ts +++ b/packages/runtime-core/src/featureFlags.ts @@ -8,24 +8,28 @@ import { getGlobalThis } from '@vue/shared' * istanbul-ignore-next */ export function initFeatureFlags() { - let needWarn = false + const needWarn = [] if (typeof __FEATURE_OPTIONS_API__ !== 'boolean') { - needWarn = true + __DEV__ && needWarn.push(`__VUE_OPTIONS_API__`) getGlobalThis().__VUE_OPTIONS_API__ = true } if (typeof __FEATURE_PROD_DEVTOOLS__ !== 'boolean') { - needWarn = true + __DEV__ && needWarn.push(`__VUE_PROD_DEVTOOLS__`) getGlobalThis().__VUE_PROD_DEVTOOLS__ = false } - if (__DEV__ && needWarn) { + if (__DEV__ && needWarn.length) { + const multi = needWarn.length > 1 console.warn( - `You are running the esm-bundler build of Vue. It is recommended to ` + - `configure your bundler to explicitly replace feature flag globals ` + - `with boolean literals to get proper tree-shaking in the final bundle. ` + - `See http://link.vuejs.org/feature-flags for more details.` + `Feature flag${multi ? `s` : ``} ${needWarn.join(', ')} ${ + multi ? `are` : `is` + } not explicitly defined. You are running the esm-bundler build of Vue, ` + + `which expects these compile-time feature flags to be globally injected ` + + `via the bundler config in order to get better tree-shaking in the ` + + `production bundle.\n\n` + + `For more details, see http://link.vuejs.org/feature-flags.` ) } }