Skip to content

Commit 3c13abb

Browse files
authored
breaking: split devtools production feature flags (#434)
To provide experimental features for `@intlify/devtools`, feature flags have been separated as follows. - `__VUE_I18N_PROD_DEVTOOLS__`: enable/disable vue-devtools support in production, default: false - `__INTLIFY_PROD_DEVTOOLS__`: enable/disable `@intlify/devtools` support in production, default: false Previously, `__INTLIFY_PROD_DEVTOOLS__` setting flagged the use of both vue-devtools and `@intlify/devtools` in production. In later v9.1, The feature flags for vue-devtools are now enabled/disabled by setting `__VUE_I18N_PROD_DEVTOOLS__`.
1 parent ed2b31e commit 3c13abb

File tree

13 files changed

+48
-37
lines changed

13 files changed

+48
-37
lines changed

docs/guide/advanced/optimization.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ The `esm-bundler` builds now exposes global feature flags that can be overwritte
9393

9494
- `__VUE_I18N_FULL_INSTALL__` (enable/disable, in addition to vue-i18n APIs, components and directives all fully support installation: `true`)
9595
- `__VUE_I18N_LEGACY_API__` (enable/disable vue-i18n legacy style APIs support, default: `true`)
96-
- `__INTLIFY_PROD_DEVTOOLS__` (enable/disable intlify-devtools and vue-devtools support in production, default: `false`)
96+
- `__VUE_I18N_PROD_DEVTOOLS__` (enable/disable vue-devtools support in production, default: `false`)
97+
- `__INTLIFY_PROD_DEVTOOLS__` (enable/disable `@intlify/devtools` support in production, default: `false`)
98+
99+
:::warning NOTICE
100+
`__INTLIFY_PROD_DEVTOOLS__` flag is experimental, and `@intlify/devtools` is WIP yet.
97101

98102
The build will work without configuring these flags, however it is **strongly recommended** to properly configure them in order to get proper tree shaking in the final bundle. To configure these flags:
99103

packages/core-base/src/context.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ export function createCoreContext<
309309
}
310310

311311
// NOTE: experimental !!
312-
// TODO: should be checked with feature flags
313-
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
312+
if (__DEV__ || __FEATURE_PROD_INTLIFY_DEVTOOLS__) {
314313
initI18nDevTools(context, VERSION, __meta)
315314
}
316315

packages/core-base/src/translate.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ export function translate<Messages, Message = string>(
384384
const ret = postTranslation ? postTranslation(messaged) : messaged
385385

386386
// NOTE: experimental !!
387-
// TODO: should be checked with feature flags
388-
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
387+
if (__DEV__ || __FEATURE_PROD_INTLIFY_DEVTOOLS__) {
389388
const payloads = {
390389
timestamp: Date.now(),
391390
key:

packages/global.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ declare let __BUNDLE_FILENAME__: string
1111
declare let __COMMIT__: string
1212

1313
// Feature flags
14-
declare let __FEATURE_PROD_DEVTOOLS__: boolean
14+
declare let __FEATURE_PROD_VUE_DEVTOOLS__: boolean
15+
declare let __FEATURE_PROD_INTLIFY_DEVTOOLS__: boolean
1516
declare let __FEATURE_LEGACY_API__: boolean
1617
declare let __FEATURE_FULL_INSTALL__: boolean
1718
declare let __FEATURE_ESM_BUNDLER_WARN__: boolean

packages/size-check-vue-i18n/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const config = {
2828
__VUE_PROD_DEVTOOLS__: false,
2929
__VUE_I18N_LEGACY_API__: false,
3030
__VUE_I18N_FULL_INSTALL__: false,
31+
__VUE_I18N_PROD_DEVTOOLS__: false,
3132
__INTLIFY_PROD_DEVTOOLS__: false,
3233
'process.env.NODE_ENV': JSON.stringify('production')
3334
}),

packages/vue-i18n/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Internationalization plugin for Vue.js
77
### From CDN or without a Bundler
88

99
- **`vue-i18n(.runtime).global(.prod).js`**:
10+
1011
- For direct use via `<script src="...">` in the browser. Exposes the `VueI18n` global
11-
- Note that global builds are not [UMD](https://github.com/umdjs/umd) builds. They are built as [IIFEs](https://developer.mozilla.org/en-US/docs/Glossary/IIFE) and is only meant for direct use via `<script src="...">`
12+
- Note that global builds are not [UMD](https://github.com/umdjs/umd) builds. They are built as [IIFEs](https://developer.mozilla.org/en-US/docs/Glossary/IIFE) and is only meant for direct use via `<script src="...">`
1213
- In-browser locale messages compilation:
1314
- **`vue-i18n.global.js`** is the "full" build that includes both the compiler and the runtime so it supports compiling locale messages on the fly
1415
- **`vue-i18n.runtime.global.js`** contains only the runtime and requires locale messages to be pre-compiled during a build step
@@ -51,7 +52,10 @@ The `esm-bundler` builds now exposes global feature flags that can be overwritte
5152

5253
- `__VUE_I18N_FULL_INSTALL__` (enable/disable, in addition to vue-i18n APIs, components and directives all fully support installation: `true`)
5354
- `__VUE_I18N_LEGACY_API__` (enable/disable vue-i18n legacy style APIs support, default: `true`)
54-
- `__INTLIFY_PROD_DEVTOOLS__` (enable/disable intlify-devtools and vue-devtools support in production, default: `false`)
55+
- `__VUE_I18N_PROD_DEVTOOLS__` (enable/disable vue-devtools support in production, default: `false`)
56+
- `__INTLIFY_PROD_DEVTOOLS__` (enable/disable `@intlify/devtools` support in production, default: `false`)
57+
58+
> NOTE: `__INTLIFY_PROD_DEVTOOLS__` flag is experimental, and `@intlify/devtools` is WIP yet.
5559
5660
The build will work without configuring these flags, however it is **strongly recommended** to properly configure them in order to get proper tree shaking in the final bundle. To configure these flags:
5761

packages/vue-i18n/src/devtools.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,22 @@ export async function enableDevTools<
7171
})
7272

7373
api.on.inspectComponent(({ componentInstance, instanceData }) => {
74-
if (componentInstance.vnode.el.__INTLIFY__ && instanceData) {
74+
if (componentInstance.vnode.el.__VUE_I18N__ && instanceData) {
7575
if (i18n.mode === 'legacy') {
7676
// ignore global scope on legacy mode
7777
if (
78-
componentInstance.vnode.el.__INTLIFY__ !==
78+
componentInstance.vnode.el.__VUE_I18N__ !==
7979
((i18n.global as unknown) as VueI18nInternal).__composer
8080
) {
8181
inspectComposer(
8282
instanceData,
83-
componentInstance.vnode.el.__INTLIFY__ as Composer
83+
componentInstance.vnode.el.__VUE_I18N__ as Composer
8484
)
8585
}
8686
} else {
8787
inspectComposer(
8888
instanceData,
89-
componentInstance.vnode.el.__INTLIFY__ as Composer
89+
componentInstance.vnode.el.__VUE_I18N__ as Composer
9090
)
9191
}
9292
}
@@ -157,9 +157,9 @@ function updateComponentTreeTags<
157157
const global = i18n.mode === 'composition'
158158
? i18n.global
159159
: (i18n.global as unknown as VueI18nInternal).__composer
160-
if (instance && instance.vnode.el.__INTLIFY__) {
160+
if (instance && instance.vnode.el.__VUE_I18N__) {
161161
// add custom tags local scope only
162-
if (instance.vnode.el.__INTLIFY__ !== global) {
162+
if (instance.vnode.el.__VUE_I18N__ !== global) {
163163
const label =
164164
instance.type.name || instance.type.displayName || instance.type.__file
165165
const tag = {

packages/vue-i18n/src/i18n.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ export function createI18n<
359359
},
360360
// install plugin
361361
async install(app: App, ...options: unknown[]): Promise<void> {
362-
if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && !__NODE_JS__) {
362+
if ((__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) && !__NODE_JS__) {
363363
app.__VUE_I18N__ = i18n as _I18n
364364
}
365365

@@ -400,7 +400,7 @@ export function createI18n<
400400
}
401401

402402
// setup vue-devtools plugin
403-
if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && !__NODE_JS__) {
403+
if ((__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) && !__NODE_JS__) {
404404
const ret = await enableDevTools(app, i18n as _I18n)
405405
if (!ret) {
406406
throw createI18nError(I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN)
@@ -721,11 +721,11 @@ function setupLifeCycle<Messages, DateTimeFormats, NumberFormats>(
721721
onMounted(() => {
722722
// inject composer instance to DOM for intlify-devtools
723723
if (
724-
(__DEV__ || __FEATURE_PROD_DEVTOOLS__) &&
724+
(__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) &&
725725
!__NODE_JS__ &&
726726
target.vnode.el
727727
) {
728-
target.vnode.el.__INTLIFY__ = composer
728+
target.vnode.el.__VUE_I18N__ = composer
729729
emitter = createEmitter<VueDevToolsEmitterEvents>()
730730
// eslint-disable-next-line @typescript-eslint/no-explicit-any
731731
const _composer = composer as any
@@ -737,16 +737,16 @@ function setupLifeCycle<Messages, DateTimeFormats, NumberFormats>(
737737
onUnmounted(() => {
738738
// remove composer instance from DOM for intlify-devtools
739739
if (
740-
(__DEV__ || __FEATURE_PROD_DEVTOOLS__) &&
740+
(__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) &&
741741
!__NODE_JS__ &&
742742
target.vnode.el &&
743-
target.vnode.el.__INTLIFY__
743+
target.vnode.el.__VUE_I18N__
744744
) {
745745
emitter && emitter.off('*', addTimelineEvent)
746746
// eslint-disable-next-line @typescript-eslint/no-explicit-any
747747
const _composer = composer as any
748748
_composer[DisableEmitter] && _composer[DisableEmitter]()
749-
delete target.vnode.el.__INTLIFY__
749+
delete target.vnode.el.__VUE_I18N__
750750
}
751751
i18n.__deleteInstance(target)
752752
}, target)

packages/vue-i18n/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ export { I18nPluginOptions } from './plugin'
7979
export { VERSION } from './misc'
8080

8181
// NOTE: experimental !!
82-
// TODO: should be checked with feature flags
83-
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
82+
if (__DEV__ || __FEATURE_PROD_INTLIFY_DEVTOOLS__) {
8483
const target = getGlobalThis()
84+
target.__INTLIFY__ = true
8585
setDevToolsHook(target.__INTLIFY_DEVTOOLS_GLOBAL_HOOK__)
8686
}
8787

8888
if (__ESM_BUNDLER__ && !__TEST__) {
8989
initFeatureFlags()
9090
}
9191

92-
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
92+
if (__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) {
9393
initDev()
9494
}

packages/vue-i18n/src/misc.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ export function initFeatureFlags(): void {
2727
getGlobalThis().__VUE_I18N_LEGACY_API__ = true
2828
}
2929

30-
if (typeof __FEATURE_PROD_DEVTOOLS__ !== 'boolean') {
30+
if (typeof __FEATURE_PROD_VUE_DEVTOOLS__ !== 'boolean') {
3131
needWarn = true
32+
getGlobalThis().__VUE_I18N_PROD_DEVTOOLS__ = false
33+
}
34+
35+
if (typeof __FEATURE_PROD_INTLIFY_DEVTOOLS__ !== 'boolean') {
3236
getGlobalThis().__INTLIFY_PROD_DEVTOOLS__ = false
3337
}
3438

@@ -50,10 +54,6 @@ export function initFeatureFlags(): void {
5054
* istanbul-ignore-next
5155
*/
5256
export function initDev(): void {
53-
const target = getGlobalThis()
54-
55-
target.__INTLIFY__ = true
56-
5757
if (__BROWSER__) {
5858
console.info(
5959
`You are running a development build of vue-i18n.\n` +

0 commit comments

Comments
 (0)