From 316ba19d19103b74b40a48a02471671014be198f Mon Sep 17 00:00:00 2001 From: zjxxxxxxxxx <954270063@qq.com> Date: Sat, 9 Dec 2023 10:29:39 +0800 Subject: [PATCH] fix: `process.env.NODE_ENV` is undefined --- src/core/index.ts | 3 ++- src/core/isDev.ts | 3 +++ src/vue.ts | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 src/core/isDev.ts diff --git a/src/core/index.ts b/src/core/index.ts index d6727a0..04969fc 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -2,11 +2,12 @@ import { type UnpluginFactory, createUnplugin } from 'unplugin'; import { createFilter } from '@rollup/pluginutils'; import { type ResolvedOptions, type Options } from '../types'; import { TRACE_ID } from './constants'; +import { isDev } from './isDev'; import { parse_ID } from './parse_ID'; import { transform } from './transform'; export const unpluginFactory: UnpluginFactory = (options = {}) => { - if (process.env.NODE_ENV !== 'development') { + if (!isDev()) { return { name: 'unplugin-vue-source', }; diff --git a/src/core/isDev.ts b/src/core/isDev.ts new file mode 100644 index 0000000..c56b541 --- /dev/null +++ b/src/core/isDev.ts @@ -0,0 +1,3 @@ +export function isDev() { + return !(process.env.NODE_ENV && process.env.NODE_ENV !== 'development'); +} diff --git a/src/vue.ts b/src/vue.ts index 4f2baa4..660a315 100644 --- a/src/vue.ts +++ b/src/vue.ts @@ -1,7 +1,8 @@ import { TRACE_ID } from './core/constants'; +import { isDev } from './core/isDev'; export default { install(app: any) { - if (process.env.NODE_ENV === 'development') { + if (isDev()) { app.mixin({ props: { [TRACE_ID]: String,