diff --git a/rollup.config.js b/rollup.config.js index 99feba79b..b6ea3cc35 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -197,7 +197,11 @@ function createReplacePlugin( ...(isProduction && isBrowserBuild ? { 'emitError(': `/*#__PURE__*/ emitError(`, - 'createCompileError(': `/*#__PURE__*/ createCompileError(` + 'createCompileError(': `/*#__PURE__*/ createCompileError(`, + 'function createCoreError(': `/*#__PURE__*/ function createCoreError(`, + 'throw createCoreError(': `throw Error(`, + 'function createI18nError(': `/*#__PURE__*/ function createI18nError(`, + 'throw createI18nError(': `throw Error(` } : {}) } diff --git a/src/global.d.ts b/src/global.d.ts index 67977465f..efe83b2c3 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -3,6 +3,7 @@ declare let __DEV__: boolean declare let __TEST__: boolean declare let __ESM_BUNDLER__: boolean declare let __BROWSER__: boolean +declare let __NODE_JS__: boolean declare let __VERSION__: string // Feature flags diff --git a/src/i18n.ts b/src/i18n.ts index cb6bf718d..c56ce9fbb 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -280,7 +280,7 @@ export function createI18n< }, // install plugin async install(app: App, ...options: unknown[]): Promise { - if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) { + if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && !__NODE_JS__) { app.__VUE_I18N__ = i18n as _I18n } @@ -313,7 +313,7 @@ export function createI18n< ) } - if (__DEV__) { + if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && !__NODE_JS__) { const ret = await enableDevTools(app, i18n as _I18n) if (!ret) { throw createI18nError(I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN) @@ -366,7 +366,7 @@ export function createI18n< } } - if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) { + if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && !__NODE_JS__) { devtoolsRegisterI18n(i18n, VERSION) } @@ -582,7 +582,11 @@ function setupLifeCycle( onMounted(() => { // inject composer instance to DOM for intlify-devtools - if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && target.vnode.el) { + if ( + (__DEV__ || __FEATURE_PROD_DEVTOOLS__) && + !__NODE_JS__ && + target.vnode.el + ) { target.vnode.el.__INTLIFY__ = composer emitter = createEmitter() // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -596,6 +600,7 @@ function setupLifeCycle( // remove composer instance from DOM for intlify-devtools if ( (__DEV__ || __FEATURE_PROD_DEVTOOLS__) && + !__NODE_JS__ && target.vnode.el && target.vnode.el.__INTLIFY__ ) { diff --git a/src/mixin.ts b/src/mixin.ts index 6e633f14c..4459d61bd 100644 --- a/src/mixin.ts +++ b/src/mixin.ts @@ -91,7 +91,7 @@ export function defineMixin( }, mounted(): void { - if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) { + if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && !__NODE_JS__) { this.$el.__INTLIFY__ = this.$i18n.__composer const emitter: DevToolsEmitter = (this.__emitter = createEmitter< DevToolsEmitterEvents @@ -113,7 +113,7 @@ export function defineMixin( throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR) } - if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) { + if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && !__NODE_JS__) { if (this.__emitter) { this.__emitter.off('*', addTimelineEvent) delete this.__emitter diff --git a/yarn.lock b/yarn.lock index 3ffa96537..ea753dc06 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7998,9 +7998,9 @@ typescript@~3.9.7: integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw== uglify-js@^3.1.4: - version "3.11.2" - resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.11.2.tgz#9f50325544273c27b20e586def140e7726c525ea" - integrity sha512-G440NU6fewtnQftSgqRV1r2A5ChKbU1gqFCJ7I8S7MPpY/eZZfLGefaY6gUZYiWebMaO+txgiQ1ZyLDuNWJulg== + version "3.11.3" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.11.3.tgz#b2f8c87826344f091ba48c417c499d6cba5d5786" + integrity sha512-wDRziHG94mNj2n3R864CvYw/+pc9y/RNImiTyrrf8BzgWn75JgFSwYvXrtZQMnMnOp/4UTrf3iCSQxSStPiByA== union-value@^1.0.0: version "1.0.1"