From f60874c8e12554586ee6c18d4bc354715c9d6ad1 Mon Sep 17 00:00:00 2001 From: Jeff Yang <32727188+ydcjeff@users.noreply.github.com> Date: Sun, 12 Dec 2021 13:09:53 +0630 Subject: [PATCH] fix: allow overwriting `define` options in vue & vue-jsx plugins (#6072) --- packages/plugin-vue-jsx/index.js | 11 ++++++++--- packages/plugin-vue/src/index.ts | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/plugin-vue-jsx/index.js b/packages/plugin-vue-jsx/index.js index a520ae17..56c50fe2 100644 --- a/packages/plugin-vue-jsx/index.js +++ b/packages/plugin-vue-jsx/index.js @@ -48,6 +48,12 @@ function vueJsxPlugin(options = {}) { name: 'vite:vue-jsx', config(config) { + const optionsApi = config.define + ? config.define.__VUE_OPTIONS_API__ + : undefined + const devTools = config.define + ? config.define.__VUE_PROD_DEVTOOLS__ + : undefined return { // only apply esbuild to ts files // since we are handling jsx and tsx now @@ -55,9 +61,8 @@ function vueJsxPlugin(options = {}) { include: /\.ts$/ }, define: { - __VUE_OPTIONS_API__: true, - __VUE_PROD_DEVTOOLS__: false, - ...config.define + __VUE_OPTIONS_API__: optionsApi != null ? optionsApi : true, + __VUE_PROD_DEVTOOLS__: devTools != null ? devTools : false } } }, diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index 4df81155..26e2709b 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -130,8 +130,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { config() { return { define: { - __VUE_OPTIONS_API__: true, - __VUE_PROD_DEVTOOLS__: false + __VUE_OPTIONS_API__: config.define?.__VUE_OPTIONS_API__ ?? true, + __VUE_PROD_DEVTOOLS__: config.define?.__VUE_PROD_DEVTOOLS__ ?? false }, ssr: { external: ['vue', '@vue/server-renderer']